Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OUT-1268 | 500 Internal Server Error for Profile Manager #42

Merged
merged 4 commits into from
Jan 16, 2025
Merged
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
12 changes: 12 additions & 0 deletions src/app/api/client-profile-updates/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion src/app/manage/views/ManagePageContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<InputContainer key={key}>
<Typography variant="md">{field.name}</Typography>
<ToolTipDecider show={!field.permission.includes('EDIT')}>
<StyledTextInput
value={profileData?.[field.key] || ''}
value={fieldValue || ''}
variant="outlined"
padding="8px 12px"
disabled={!field.permission.includes('EDIT')}
key={key}
onChange={(e) => {
setProfileData((prev: any) => {
if (field.key === 'address') {
return { ...prev, [field.key]: { fullAddress: e.target.value } };
}
return { ...prev, [field.key]: e.target.value };
});
}}
Expand Down
18 changes: 17 additions & 1 deletion src/components/table/cellRenderers/HistoryCellRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export const HistoryCellRenderer = ({ value }: { value: { row: any; key: string
</Typography>
)}
<Typography variant="bodyMd" onMouseEnter={handleMouseEnter} onMouseLeave={handleMouseLeave}>
{data?.value}
{typeof data?.value === 'object' ? data?.value.fullAddress || '' : data?.value}
</Typography>

<Popper id={id} open={open} anchorEl={anchorEl}>
Expand Down Expand Up @@ -267,6 +267,22 @@ const HistoryList = ({ updateHistory }: { updateHistory: any }) => {
</Stack>
);
}
if (typeof history?.value === 'object') {
if ('fullAddress' in history?.value) {
return (
<Stack key={key} direction="row" alignItems="flex-start" columnGap={3}>
<Typography variant="bodyMd" fontSize={20}>
&#x2022;
</Typography>
<Typography variant="bodySm" key={key}>
{history.value.fullAddress}
</Typography>
</Stack>
);
} else {
return <></>;
}
}
return (
<Stack key={key} direction="row" alignItems="flex-start" columnGap={3}>
<Typography variant="bodyMd" fontSize={20}>
Expand Down
2 changes: 1 addition & 1 deletion src/lib/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function createMapLookup<T extends Record<string, unknown>>(
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) {
Expand Down
6 changes: 5 additions & 1 deletion src/types/clientProfileUpdates.ts
Original file line number Diff line number Diff line change
@@ -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<typeof CustomFieldUpdatesSchema>;

export const ClientProfileUpdatesRequestSchema = z.object({
Expand Down
12 changes: 10 additions & 2 deletions src/types/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof ClientResponseSchema>;

Expand Down Expand Up @@ -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<typeof ClientRequestSchema>;
Loading