Skip to content

Commit

Permalink
Remove "Invitation code" and "date of birth" fields from UserForm (#81)
Browse files Browse the repository at this point in the history
# Remove "Invitation code" and "date of birth" fields from UserForm

## ⚙️ Release Notes 
* Remove "Invitation code" and "date of birth" fields from UserForm
* Improve empty organization id handling


### Code of Conduct & Contributing Guidelines 

By submitting creating this pull request, you agree to follow our [Code
of
Conduct](https://github.com/StanfordBDHG/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordBDHG/.github/blob/main/CONTRIBUTING.md):
- [x] I agree to follow the [Code of
Conduct](https://github.com/StanfordBDHG/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordBDHG/.github/blob/main/CONTRIBUTING.md).
  • Loading branch information
arkadiuszbachorski authored Nov 4, 2024
1 parent d694c6f commit 176bfad
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 34 deletions.
39 changes: 8 additions & 31 deletions routes/~_dashboard/~users/UserForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { z } from 'zod'
import { type Organization, type User } from '@/modules/firebase/models'
import { useUser } from '@/modules/firebase/UserProvider'
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,
Expand All @@ -27,9 +26,7 @@ export const userFormSchema = z
.object({
email: z.string().email().min(1, 'Email is required'),
displayName: z.string(),
invitationCode: z.string(),
dateOfBirth: z.date().optional(),
organizationId: z.string().optional(),
organizationId: z.string().nullable(),
type: z.nativeEnum(UserType),
})
.superRefine((schema, ctx) => {
Expand All @@ -47,7 +44,7 @@ export type UserFormSchema = z.infer<typeof userFormSchema>
interface UserFormProps {
organizations: Array<Pick<Organization, 'name' | 'id'>>
userInfo?: Pick<UserInfo, 'email' | 'displayName' | 'uid'>
user?: Pick<User, 'organization' | 'invitationCode' | 'dateOfBirth'>
user?: Pick<User, 'organization'>
type?: UserType
onSubmit: (data: UserFormSchema) => Promise<void>
}
Expand All @@ -70,9 +67,7 @@ export const UserForm = ({
organizationId:
(authUser.user.type === UserType.owner ?
authUser.user.organization
: user?.organization) ?? undefined,
invitationCode: user?.invitationCode ?? '',
dateOfBirth: user?.dateOfBirth ? new Date(user.dateOfBirth) : undefined,
: user?.organization) ?? null,
},
})

Expand All @@ -94,35 +89,17 @@ export const UserForm = ({
label="Display name"
render={({ field }) => <Input {...field} />}
/>
<Field
control={form.control}
name="dateOfBirth"
label="Date of Birth"
render={({ field }) => (
<DatePicker
mode="single"
selected={field.value}
onSelect={(date) => field.onChange(date)}
defaultMonth={field.value}
toYear={new Date().getFullYear()}
/>
)}
/>
{isEdit && (
<Field
control={form.control}
name="invitationCode"
label="Invitation code"
render={({ field }) => <Input {...field} />}
/>
)}
{authUser.user.type === UserType.admin && (
<Field
control={form.control}
name="organizationId"
label="Organization"
render={({ field }) => (
<Select onValueChange={field.onChange} {...field}>
<Select
{...field}
onValueChange={field.onChange}
value={field.value ?? undefined}
>
<SelectTrigger>
<SelectValue placeholder="Organization" />
</SelectTrigger>
Expand Down
2 changes: 0 additions & 2 deletions routes/~_dashboard/~users/~$id.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ const UserPage = () => {
email: form.email,
}
const userData = {
invitationCode: form.invitationCode,
organization: form.organizationId,
type: form.type,
dateOfBirth: form.dateOfBirth?.toISOString(),
}
if (resourceType === 'user') {
await callables.updateUserInformation({
Expand Down
1 change: 0 additions & 1 deletion routes/~_dashboard/~users/~invite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ const InviteUserPage = () => {
user: {
...(form.organizationId ? { organization: form.organizationId } : {}),
type: form.type,
dateOfBirth: form.dateOfBirth?.toISOString(),
},
})
void navigate({ to: routes.users.user(result.data.id) })
Expand Down

0 comments on commit 176bfad

Please sign in to comment.