diff --git a/src/app/api/client-profile-updates/route.ts b/src/app/api/client-profile-updates/route.ts index e070066..3d24450 100644 --- a/src/app/api/client-profile-updates/route.ts +++ b/src/app/api/client-profile-updates/route.ts @@ -17,7 +17,19 @@ export async function POST(request: NextRequest) { //todo: check access const copilotClient = new CopilotAPI(clientProfileUpdateRequest.data.token); const client: ClientResponse = await copilotClient.getClient(clientProfileUpdateRequest.data.clientId); + + for (const key of Object.keys(clientProfileUpdateRequest.data.form)) { + // Yes, this code sucks. No, I don't have an option right now + // TODO: Cleanup once we support better fields for address + const data = clientProfileUpdateRequest?.data?.form?.[key]; + const addressableData = data as { fullAddress: string }; + if (addressableData?.fullAddress) { + clientProfileUpdateRequest.data.form[key] = addressableData.fullAddress; + } + } + const clientUpdateResponse = await copilotClient.updateClient(clientProfileUpdateRequest.data.clientId, { + // @ts-expect-error temporary support for address type customFields: clientProfileUpdateRequest.data.form, }); // NOTE: If you pass empty string as value to a custom field, that key will be deleted from the copilot api diff --git a/src/app/manage/views/ManagePageContainer.tsx b/src/app/manage/views/ManagePageContainer.tsx index 9050765..89df331 100644 --- a/src/app/manage/views/ManagePageContainer.tsx +++ b/src/app/manage/views/ManagePageContainer.tsx @@ -127,18 +127,25 @@ export const ManagePageContainer = ({ {allowedCustomField && order(allowedCustomField).map((field: any, key: number) => { if (field?.type !== 'multiSelect') { + let fieldValue = profileData?.[field.key]; + if (field?.key === 'address') { + fieldValue = profileData?.[field.key]?.fullAddress; + } return ( {field.name} { setProfileData((prev: any) => { + if (field.key === 'address') { + return { ...prev, [field.key]: { fullAddress: e.target.value } }; + } return { ...prev, [field.key]: e.target.value }; }); }} diff --git a/src/components/table/cellRenderers/HistoryCellRenderer.tsx b/src/components/table/cellRenderers/HistoryCellRenderer.tsx index 534e007..c1b2fad 100644 --- a/src/components/table/cellRenderers/HistoryCellRenderer.tsx +++ b/src/components/table/cellRenderers/HistoryCellRenderer.tsx @@ -201,7 +201,7 @@ export const HistoryCellRenderer = ({ value }: { value: { row: any; key: string )} - {data?.value} + {typeof data?.value === 'object' ? data?.value.fullAddress || '' : data?.value} @@ -267,6 +267,22 @@ const HistoryList = ({ updateHistory }: { updateHistory: any }) => { ); } + if (typeof history?.value === 'object') { + if ('fullAddress' in history?.value) { + return ( + + + • + + + {history.value.fullAddress} + + + ); + } else { + return <>; + } + } return ( diff --git a/src/lib/helper.ts b/src/lib/helper.ts index cdff0d2..ba7ad31 100644 --- a/src/lib/helper.ts +++ b/src/lib/helper.ts @@ -43,7 +43,7 @@ export function createMapLookup>( return result; } -export function getSelectedOptions(portalCustomField: CustomField, value: string | string[]) { +export function getSelectedOptions(portalCustomField: CustomField, value: string | string[] | object) { const options: unknown[] = []; if (portalCustomField?.type === 'multiSelect' && value && Array.isArray(value) && portalCustomField.options) { diff --git a/src/types/clientProfileUpdates.ts b/src/types/clientProfileUpdates.ts index dce7001..dfee707 100644 --- a/src/types/clientProfileUpdates.ts +++ b/src/types/clientProfileUpdates.ts @@ -1,6 +1,10 @@ import { z } from 'zod'; -export const CustomFieldUpdatesSchema = z.record(z.union([z.string(), z.array(z.string())]).nullable()); +export const AddressCustomFieldSchema = z.record(z.string(), z.any()); + +export const CustomFieldUpdatesSchema = z.record( + z.union([z.string(), z.array(z.string()), AddressCustomFieldSchema]).nullable(), +); export type CustomFieldUpdates = z.infer; export const ClientProfileUpdatesRequestSchema = z.object({ diff --git a/src/types/common.ts b/src/types/common.ts index 08ee957..9574565 100644 --- a/src/types/common.ts +++ b/src/types/common.ts @@ -60,7 +60,13 @@ export const ClientResponseSchema = z.object({ companyId: z.string().optional(), status: z.string(), avatarImageUrl: z.string().nullable(), - customFields: z.record(z.string(), z.union([z.string(), z.array(z.string())]).nullable()).nullish(), + customFields: z + .record( + z.string(), + // Accomodate new address field + z.union([z.string().nullable(), z.array(z.string()).nullable(), z.record(z.string(), z.any()).nullable()]).nullable(), + ) + .nullish(), }); export type ClientResponse = z.infer; @@ -110,6 +116,8 @@ export const ClientRequestSchema = z.object({ givenName: z.string().optional(), familyName: z.string().optional(), companyId: z.string().uuid().optional(), - customFields: z.record(z.string(), z.union([z.string(), z.array(z.string())]).nullish()).nullish(), + customFields: z + .record(z.string(), z.union([z.string(), z.array(z.string())]).nullish(), z.record(z.string(), z.any())) + .nullish(), }); export type ClientRequest = z.infer;