diff --git a/src/pages/groups/groups-view/group-actions/EditGroups.tsx b/src/pages/groups/groups-view/group-actions/EditGroups.tsx index 0f3a1f5..00d560a 100644 --- a/src/pages/groups/groups-view/group-actions/EditGroups.tsx +++ b/src/pages/groups/groups-view/group-actions/EditGroups.tsx @@ -14,7 +14,8 @@ import { Button } from '@/components/ui/button' import { Label } from '@/components/ui/label' import { Input } from '@/components/ui/input' -import { GroupsApi, type GetGroupsGroupIdResponse } from '@/fineract-api' +import { GroupsApi, type PutGroupsGroupIdRequest } from '@/fineract-api' +import type { ExtendedGroupResponse } from '@/pages/groups/types' import { getConfiguration } from '@/lib/fineract-openapi' import { dateArrayToInputValue, inputToFineractDate } from '@/lib/date-utils' import { useTranslation } from 'react-i18next' @@ -28,7 +29,7 @@ const EditGroups = () => { const { t: tc } = useTranslation('common') // Local state for group + form fields - const [group, setGroup] = useState() + const [group, setGroup] = useState() const [name, setName] = useState('') const [staffId, setStaffId] = useState('') const [submittedOn, setSubmittedOn] = useState('') @@ -42,19 +43,21 @@ const EditGroups = () => { if (!id) return try { const res = await groupsApi.retrieveOne15(Number(id)) - setGroup(res.data) + const groupData = res.data as ExtendedGroupResponse + setGroup(groupData) - setName(res.data?.name ?? '') - if ((res.data as any)?.staffId) { - setStaffId(String((res.data as any).staffId)) + setName(groupData?.name ?? '') + if (groupData?.staffId) { + setStaffId(String(groupData.staffId)) } setSubmittedOn( - dateArrayToInputValue((res.data as any)?.timeline?.submittedOnDate) + dateArrayToInputValue( + groupData?.timeline?.submittedOnDate as number[] | null + ) ) setActivationOn( dateArrayToInputValue( - (res.data as any)?.timeline?.activationDate ?? - (res.data as any)?.timeline?.activatedOnDate + groupData?.timeline?.activatedOnDate as number[] | null ) ) // externalId left blank on purpose, user must fill if needed @@ -65,18 +68,22 @@ const EditGroups = () => { }, [id]) // Build staff dropdown options from API response - const staffOptions = - ((group as any)?.staffOptions ?? []).map((s: any) => ({ - id: s.id, - name: s.displayName ?? s.name ?? t('edit.staffFallback', { id: s.id }), - })) || [] + const staffOptions = (group?.staffOptions ?? []).map(s => ({ + id: s.id ?? 0, + name: s.displayName ?? s.name ?? t('edit.staffFallback', { id: s.id }), + })) // Handle submit const onSubmit = async () => { if (!id) return + const groupId = Number(id) + if (!Number.isFinite(groupId)) { + console.error('Invalid group id:', id) + return + } setSaving(true) try { - const payload: any = { + const payload: PutGroupsGroupIdRequest & Record = { name: name.trim(), locale: 'en', dateFormat: 'dd MMMM yyyy', @@ -89,6 +96,7 @@ const EditGroups = () => { if (act) payload.activationDate = act if (externalId.trim()) payload.externalId = externalId.trim() + await groupsApi.update13(groupId, payload) navigate(`/groups/${id}/general`) } catch (err) { console.error('Failed to update group', err) @@ -104,7 +112,10 @@ const EditGroups = () => { items={[ { label: tc('nav.home'), href: '/home' }, { label: t('title'), href: '/groups' }, - { label: group?.name ?? t('view.groupName'), href: `/groups/${id}/general` }, + { + label: group?.name ?? t('view.groupName'), + href: `/groups/${id}/general`, + }, { label: t('edit.breadcrumb'), current: true }, ]} /> @@ -141,8 +152,8 @@ const EditGroups = () => { { {/* Activation Date */}
- +