Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions src/pages/groups/CreateGroups.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import {
type StaffData,
} from '@/fineract-api'
import { getConfiguration } from '@/lib/fineract-openapi'
import { inputToFineractDate } from '@/lib/date-utils'
import type { ExtendedPostGroupsRequest } from '@/pages/groups/types'
import { useTranslation } from 'react-i18next'

const groupsApi = new GroupsApi(getConfiguration())
Expand Down Expand Up @@ -79,15 +81,17 @@ const CreateGroups = () => {
await groupsApi.create8({
name: formData.name,
officeId: Number(formData.officeId),
// staffId: formData.staffId,
active: formData.active,
// externalId: formData.externalId || undefined,
// submittedOnDate: formData.submittedOnDate || undefined,
// activationDate:
// formData.active && formData.activationDate
// ? formData.activationDate
// : undefined,
})
staffId: formData.staffId ? Number(formData.staffId) : undefined,
externalId: formData.externalId.trim() || undefined,
submittedOnDate: inputToFineractDate(formData.submittedOnDate),
activationDate:
formData.active && formData.activationDate
? inputToFineractDate(formData.activationDate)
: undefined,
dateFormat: 'dd MMMM yyyy',
locale: 'en',
} as ExtendedPostGroupsRequest)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
navigate('/groups')
} catch (e) {
console.error('Failed to create group', e)
Expand Down
13 changes: 8 additions & 5 deletions src/pages/groups/groups-view/group-actions/EditGroups.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import { Label } from '@/components/ui/label'
import { Input } from '@/components/ui/input'

import { GroupsApi } from '@/fineract-api'
import type { ExtendedGroupResponse } from '@/pages/groups/types'
import type {
ExtendedGroupResponse,
ExtendedPutGroupsRequest,
} from '@/pages/groups/types'
import { getConfiguration } from '@/lib/fineract-openapi'
import { dateArrayToInputValue, inputToFineractDate } from '@/lib/date-utils'
import { useTranslation } from 'react-i18next'
Expand Down Expand Up @@ -60,7 +63,7 @@ const EditGroups = () => {
groupData?.timeline?.activatedOnDate as number[] | null
)
)
// externalId left blank on purpose, user must fill if needed
setExternalId(groupData.externalId ?? '')
} catch (err) {
console.error("Can't fetch group", err)
}
Expand All @@ -78,7 +81,7 @@ const EditGroups = () => {
if (!id) return
setSaving(true)
try {
const payload: Record<string, unknown> = {
const payload: ExtendedPutGroupsRequest = {
name: name.trim(),
locale: 'en',
dateFormat: 'dd MMMM yyyy',
Expand All @@ -89,9 +92,9 @@ const EditGroups = () => {
if (sub) payload.submittedOnDate = sub
const act = inputToFineractDate(activationOn)
if (act) payload.activationDate = act
if (externalId.trim()) payload.externalId = externalId.trim()
payload.externalId = externalId.trim() || undefined

await groupsApi.update13(Number(id), { name: payload.name as string })
await groupsApi.update13(Number(id), payload)
navigate(`/groups/${id}/general`)
} catch (err) {
console.error('Failed to update group', err)
Expand Down
26 changes: 25 additions & 1 deletion src/pages/groups/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
import type { GetGroupsGroupIdResponse } from '@/fineract-api'
import type {
GetGroupsGroupIdResponse,
PostGroupsRequest,
PutGroupsGroupIdRequest,
} from '@/fineract-api'

/**
* The generated `GetGroupsGroupIdResponse` is incomplete — the real API
Expand Down Expand Up @@ -51,3 +55,23 @@ export interface ClientMember {
displayName?: string
officeName?: string
}

/**
* Fields missing from both PostGroupsRequest and PutGroupsGroupIdRequest in
* the generated OpenAPI types. Extracted here so both extended interfaces stay
* in sync if more fields are discovered later.
*/
interface GroupRequestExtras {
staffId?: number
externalId?: string
submittedOnDate?: string
activationDate?: string
dateFormat?: string
locale?: string
}

export interface ExtendedPostGroupsRequest
extends PostGroupsRequest, GroupRequestExtras {}

export interface ExtendedPutGroupsRequest
extends PutGroupsGroupIdRequest, GroupRequestExtras {}