From fa6064da8e02ae395f2c954d2fa825289a14aa4b Mon Sep 17 00:00:00 2001 From: Arkadiusz Bachorski <60391032+arkadiuszbachorski@users.noreply.github.com> Date: Wed, 7 Aug 2024 20:55:11 +0200 Subject: [PATCH 01/12] Update date types --- modules/firebase/models/baseTypes.ts | 4 ++-- modules/firebase/utils.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/firebase/models/baseTypes.ts b/modules/firebase/models/baseTypes.ts index d4cdca90..85dc6cad 100644 --- a/modules/firebase/models/baseTypes.ts +++ b/modules/firebase/models/baseTypes.ts @@ -34,8 +34,8 @@ export interface FHIRExtension { } export interface FHIRPeriod { - start?: Date - end?: Date + start?: string + end?: string } export interface FHIRRatio { diff --git a/modules/firebase/utils.ts b/modules/firebase/utils.ts index 8936ba6f..1b513717 100644 --- a/modules/firebase/utils.ts +++ b/modules/firebase/utils.ts @@ -52,9 +52,9 @@ export enum UserType { export interface User { type: UserType - dateOfBirth?: Date + dateOfBirth?: string clinician?: string - dateOfEnrollment?: Date + dateOfEnrollment?: string invitationCode?: string messagesSettings?: UserMessagesSettings organization?: string From 50a7b1b3fd6a5c06537201a104a0c7d9d0d2399f Mon Sep 17 00:00:00 2001 From: Arkadiusz Bachorski <60391032+arkadiuszbachorski@users.noreply.github.com> Date: Wed, 7 Aug 2024 21:51:05 +0200 Subject: [PATCH 02/12] Update DatePicker --- .../src/components/DatePicker/DatePicker.tsx | 46 ++++++++++--------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/packages/design-system/src/components/DatePicker/DatePicker.tsx b/packages/design-system/src/components/DatePicker/DatePicker.tsx index 3ae24155..dd63a009 100644 --- a/packages/design-system/src/components/DatePicker/DatePicker.tsx +++ b/packages/design-system/src/components/DatePicker/DatePicker.tsx @@ -9,30 +9,34 @@ import { format, isDate } from 'date-fns' import { Calendar as CalendarIcon } from 'lucide-react' import { type ComponentProps } from 'react' -import { type DayPicker } from 'react-day-picker' import { cn } from '../../utils/className' import { Button } from '../Button' import { Calendar } from '../Calendar' import { Popover, PopoverTrigger, PopoverContent } from '../Popover' -export type DatePickerProps = ComponentProps +export type DatePickerProps = ComponentProps -export const DatePicker = ({ selected, ...props }: DatePickerProps) => ( - - - - - - - - -) +export const DatePicker = (props: DatePickerProps) => { + const { selected } = props + return ( + + + + + + + + + ) +} From 32b50abd5274436211955653981d90ce75ffa0cc Mon Sep 17 00:00:00 2001 From: Arkadiusz Bachorski <60391032+arkadiuszbachorski@users.noreply.github.com> Date: Sun, 11 Aug 2024 21:13:47 +0200 Subject: [PATCH 03/12] Update createInvitation to respond with code --- app/(dashboard)/patients/invite/page.tsx | 2 +- app/(dashboard)/users/invite/page.tsx | 2 +- modules/firebase/utils.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/(dashboard)/patients/invite/page.tsx b/app/(dashboard)/patients/invite/page.tsx index 4ffeb737..26f108a9 100644 --- a/app/(dashboard)/patients/invite/page.tsx +++ b/app/(dashboard)/patients/invite/page.tsx @@ -33,7 +33,7 @@ const InvitePatientPage = async () => { organization: clinician.organization, }, }) - redirect(routes.patients.patient(result.data.code)) + redirect(routes.patients.patient(result.data.id)) } return ( diff --git a/app/(dashboard)/users/invite/page.tsx b/app/(dashboard)/users/invite/page.tsx index e343bdc1..bd356344 100644 --- a/app/(dashboard)/users/invite/page.tsx +++ b/app/(dashboard)/users/invite/page.tsx @@ -32,7 +32,7 @@ const InviteUserPage = async () => { type: form.type, }, }) - redirect(routes.users.user(result.data.code)) + redirect(routes.users.user(result.data.id)) } return ( diff --git a/modules/firebase/utils.ts b/modules/firebase/utils.ts index 1b513717..5bb552a6 100644 --- a/modules/firebase/utils.ts +++ b/modules/firebase/utils.ts @@ -201,7 +201,7 @@ export const getCallables = (functions: Functions) => ({ timeZone?: string } }, - { code: string } + { id: string } >(functions, 'createInvitation'), getUsersInformation: httpsCallable< GetUsersInformationInput, From 65a039fc5089e5a415865d037c9c90652cd39653 Mon Sep 17 00:00:00 2001 From: Arkadiusz Bachorski <60391032+arkadiuszbachorski@users.noreply.github.com> Date: Sun, 11 Aug 2024 21:16:31 +0200 Subject: [PATCH 04/12] Add dateOfBirth to createInvitation --- modules/firebase/utils.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/firebase/utils.ts b/modules/firebase/utils.ts index 5bb552a6..5f176ff0 100644 --- a/modules/firebase/utils.ts +++ b/modules/firebase/utils.ts @@ -199,6 +199,7 @@ export const getCallables = (functions: Functions) => ({ clinician?: string language?: string timeZone?: string + dateOfBirth?: string } }, { id: string } From f2035190eb1b3a6ec85c99fa0bbefd44fc114759 Mon Sep 17 00:00:00 2001 From: Arkadiusz Bachorski <60391032+arkadiuszbachorski@users.noreply.github.com> Date: Sun, 11 Aug 2024 21:17:39 +0200 Subject: [PATCH 05/12] Handle updating date for birth --- app/(dashboard)/patients/PatientForm.tsx | 20 +++++++++++++++++++- app/(dashboard)/patients/[id]/page.tsx | 1 + app/(dashboard)/patients/invite/page.tsx | 1 + app/(dashboard)/users/UserForm.tsx | 17 ++++++++++++++++- app/(dashboard)/users/[id]/page.tsx | 5 +++-- app/(dashboard)/users/invite/page.tsx | 1 + 6 files changed, 41 insertions(+), 4 deletions(-) diff --git a/app/(dashboard)/patients/PatientForm.tsx b/app/(dashboard)/patients/PatientForm.tsx index 93c05499..753e6ae6 100644 --- a/app/(dashboard)/patients/PatientForm.tsx +++ b/app/(dashboard)/patients/PatientForm.tsx @@ -9,6 +9,7 @@ import { z } from 'zod' import { type User } from '@/modules/firebase/utils' import { Button } from '@/packages/design-system/src/components/Button' +import { DatePicker } from '@/packages/design-system/src/components/DatePicker' import { Input } from '@/packages/design-system/src/components/Input' import { Select, @@ -29,6 +30,7 @@ export const patientFormSchema = z.object({ displayName: z.string(), invitationCode: z.string(), clinician: z.string(), + dateOfBirth: z.date().optional(), }) export type PatientFormSchema = z.infer @@ -40,7 +42,10 @@ interface PatientFormProps { email: string | null }> userInfo?: Pick - user?: Pick + user?: Pick< + User, + 'organization' | 'invitationCode' | 'clinician' | 'dateOfBirth' + > onSubmit: (data: PatientFormSchema) => Promise clinicianPreselectId?: string } @@ -60,6 +65,7 @@ export const PatientForm = ({ displayName: userInfo?.displayName ?? '', invitationCode: user?.invitationCode ?? '', clinician: user?.clinician ?? clinicianPreselectId ?? '', + dateOfBirth: user?.dateOfBirth ? new Date(user.dateOfBirth) : undefined, }, }) @@ -81,6 +87,18 @@ export const PatientForm = ({ label="Display name" render={({ field }) => } /> + ( + field.onChange(date)} + /> + )} + /> {isEdit && ( { invitationCode: form.invitationCode, clinician: form.clinician, organization: clinician.organization, + dateOfBirth: form.dateOfBirth?.toISOString(), } if (resourceType === 'user') { await callables.updateUserInformation({ diff --git a/app/(dashboard)/patients/invite/page.tsx b/app/(dashboard)/patients/invite/page.tsx index 26f108a9..e4489a8f 100644 --- a/app/(dashboard)/patients/invite/page.tsx +++ b/app/(dashboard)/patients/invite/page.tsx @@ -31,6 +31,7 @@ const InvitePatientPage = async () => { type: UserType.patient, clinician: form.clinician, organization: clinician.organization, + dateOfBirth: form.dateOfBirth?.toISOString(), }, }) redirect(routes.patients.patient(result.data.id)) diff --git a/app/(dashboard)/users/UserForm.tsx b/app/(dashboard)/users/UserForm.tsx index 6f6ffc3d..367ad4c3 100644 --- a/app/(dashboard)/users/UserForm.tsx +++ b/app/(dashboard)/users/UserForm.tsx @@ -14,6 +14,7 @@ import { UserType, } from '@/modules/firebase/utils' import { Button } from '@/packages/design-system/src/components/Button' +import { DatePicker } from '@/packages/design-system/src/components/DatePicker' import { Input } from '@/packages/design-system/src/components/Input' import { Select, @@ -31,6 +32,7 @@ export const userFormSchema = z email: z.string().min(1, 'Email is required'), displayName: z.string(), invitationCode: z.string(), + dateOfBirth: z.date().optional(), organizationId: z.string().optional(), type: z.nativeEnum(UserType), }) @@ -49,7 +51,7 @@ export type UserFormSchema = z.infer interface UserFormProps { organizations: Array> userInfo?: Pick - user?: Pick + user?: Pick type?: UserType onSubmit: (data: UserFormSchema) => Promise } @@ -74,6 +76,7 @@ export const UserForm = ({ authUser.user.organization : user?.organization, invitationCode: user?.invitationCode ?? '', + dateOfBirth: user?.dateOfBirth ? new Date(user.dateOfBirth) : undefined, }, }) @@ -95,6 +98,18 @@ export const UserForm = ({ label="Display name" render={({ field }) => } /> + ( + field.onChange(date)} + /> + )} + /> {isEdit && ( { } const userData = { invitationCode: form.invitationCode, - organization: form.organizationId ?? deleteField(), + organization: form.organizationId, type: form.type, + dateOfBirth: form.dateOfBirth?.toISOString(), } if (resourceType === 'user') { await callables.updateUserInformation({ diff --git a/app/(dashboard)/users/invite/page.tsx b/app/(dashboard)/users/invite/page.tsx index bd356344..82576d5f 100644 --- a/app/(dashboard)/users/invite/page.tsx +++ b/app/(dashboard)/users/invite/page.tsx @@ -30,6 +30,7 @@ const InviteUserPage = async () => { user: { ...(form.organizationId ? { organization: form.organizationId } : {}), type: form.type, + dateOfBirth: form.dateOfBirth?.toISOString(), }, }) redirect(routes.users.user(result.data.id)) From 6a10410fa9eeb2ee1ce5b4bbdfb4251fee6aa858 Mon Sep 17 00:00:00 2001 From: Arkadiusz Bachorski <60391032+arkadiuszbachorski@users.noreply.github.com> Date: Sun, 11 Aug 2024 21:25:48 +0200 Subject: [PATCH 06/12] Fix clinician validation --- app/(dashboard)/patients/PatientForm.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/(dashboard)/patients/PatientForm.tsx b/app/(dashboard)/patients/PatientForm.tsx index 753e6ae6..58615fed 100644 --- a/app/(dashboard)/patients/PatientForm.tsx +++ b/app/(dashboard)/patients/PatientForm.tsx @@ -29,7 +29,7 @@ export const patientFormSchema = z.object({ email: z.string().min(1, 'Email is required'), displayName: z.string(), invitationCode: z.string(), - clinician: z.string(), + clinician: z.string().min(1, 'Clinician is required'), dateOfBirth: z.date().optional(), }) From cd6f8cdd41c17d72091a817c429f603ebd8fa753 Mon Sep 17 00:00:00 2001 From: Arkadiusz Bachorski <60391032+arkadiuszbachorski@users.noreply.github.com> Date: Sun, 11 Aug 2024 21:26:26 +0200 Subject: [PATCH 07/12] Fix email validation --- app/(dashboard)/patients/PatientForm.tsx | 2 +- app/(dashboard)/users/UserForm.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/(dashboard)/patients/PatientForm.tsx b/app/(dashboard)/patients/PatientForm.tsx index 58615fed..01f0561b 100644 --- a/app/(dashboard)/patients/PatientForm.tsx +++ b/app/(dashboard)/patients/PatientForm.tsx @@ -26,7 +26,7 @@ import { } from '@/packages/design-system/src/modules/auth/user' export const patientFormSchema = z.object({ - email: z.string().min(1, 'Email is required'), + email: z.string().email().min(1, 'Email is required'), displayName: z.string(), invitationCode: z.string(), clinician: z.string().min(1, 'Clinician is required'), diff --git a/app/(dashboard)/users/UserForm.tsx b/app/(dashboard)/users/UserForm.tsx index 367ad4c3..0720b12f 100644 --- a/app/(dashboard)/users/UserForm.tsx +++ b/app/(dashboard)/users/UserForm.tsx @@ -29,7 +29,7 @@ import { type UserInfo } from '@/packages/design-system/src/modules/auth/user' export const userFormSchema = z .object({ - email: z.string().min(1, 'Email is required'), + email: z.string().email().min(1, 'Email is required'), displayName: z.string(), invitationCode: z.string(), dateOfBirth: z.date().optional(), From 075c338628c861416a711817b576157d1daaf333 Mon Sep 17 00:00:00 2001 From: Arkadiusz Bachorski <60391032+arkadiuszbachorski@users.noreply.github.com> Date: Mon, 12 Aug 2024 08:15:11 +0200 Subject: [PATCH 08/12] Make dateOfBirth nullable --- modules/firebase/utils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/firebase/utils.ts b/modules/firebase/utils.ts index 5f176ff0..27eda0c5 100644 --- a/modules/firebase/utils.ts +++ b/modules/firebase/utils.ts @@ -52,7 +52,7 @@ export enum UserType { export interface User { type: UserType - dateOfBirth?: string + dateOfBirth?: string | null clinician?: string dateOfEnrollment?: string invitationCode?: string @@ -199,7 +199,7 @@ export const getCallables = (functions: Functions) => ({ clinician?: string language?: string timeZone?: string - dateOfBirth?: string + dateOfBirth?: string | null } }, { id: string } From d6c1980cc2bc0d78a58ebd06c827d4b3d0c46397 Mon Sep 17 00:00:00 2001 From: Arkadiusz Bachorski <60391032+arkadiuszbachorski@users.noreply.github.com> Date: Mon, 12 Aug 2024 08:27:28 +0200 Subject: [PATCH 09/12] Set text small in text input --- packages/design-system/src/components/DatePicker/DatePicker.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/design-system/src/components/DatePicker/DatePicker.tsx b/packages/design-system/src/components/DatePicker/DatePicker.tsx index dd63a009..c52b40f8 100644 --- a/packages/design-system/src/components/DatePicker/DatePicker.tsx +++ b/packages/design-system/src/components/DatePicker/DatePicker.tsx @@ -24,7 +24,7 @@ export const DatePicker = (props: DatePickerProps) => {