From fb6656d1d4d15c7345c8d71c48993ccfb31c0505 Mon Sep 17 00:00:00 2001 From: ifranch Date: Tue, 12 Dec 2023 15:31:26 -0800 Subject: [PATCH] feat: make organization id optional for user and remove it from add/mutate input --- .../migration.sql | 8 +++ api/db/schema.prisma | 4 +- api/src/graphql/users.sdl.ts | 2 - api/types/graphql.d.ts | 5 +- web/src/components/User/UserForm/UserForm.tsx | 52 +++++++++---------- web/types/graphql.d.ts | 2 - 6 files changed, 37 insertions(+), 36 deletions(-) create mode 100644 api/db/migrations/20231212224549_update_organization_id_to_optional_for_user/migration.sql diff --git a/api/db/migrations/20231212224549_update_organization_id_to_optional_for_user/migration.sql b/api/db/migrations/20231212224549_update_organization_id_to_optional_for_user/migration.sql new file mode 100644 index 00000000..1316b69b --- /dev/null +++ b/api/db/migrations/20231212224549_update_organization_id_to_optional_for_user/migration.sql @@ -0,0 +1,8 @@ +-- DropForeignKey +ALTER TABLE "User" DROP CONSTRAINT "User_organizationId_fkey"; + +-- AlterTable +ALTER TABLE "User" ALTER COLUMN "organizationId" DROP NOT NULL; + +-- AddForeignKey +ALTER TABLE "User" ADD CONSTRAINT "User_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE SET NULL ON UPDATE CASCADE; diff --git a/api/db/schema.prisma b/api/db/schema.prisma index a2fe5d6d..92d075b8 100644 --- a/api/db/schema.prisma +++ b/api/db/schema.prisma @@ -35,12 +35,12 @@ model User { email String name String? agencyId Int? - organizationId Int + organizationId Int? roleId Int? createdAt DateTime @default(now()) @db.Timestamptz(6) updatedAt DateTime @updatedAt @db.Timestamptz(6) agency Agency? @relation(fields: [agencyId], references: [id]) - organization Organization @relation(fields: [organizationId], references: [id]) + organization Organization? @relation(fields: [organizationId], references: [id]) role Role? @relation(fields: [roleId], references: [id]) certified ReportingPeriod[] uploaded Upload[] diff --git a/api/src/graphql/users.sdl.ts b/api/src/graphql/users.sdl.ts index 89154b52..a80124a7 100644 --- a/api/src/graphql/users.sdl.ts +++ b/api/src/graphql/users.sdl.ts @@ -27,7 +27,6 @@ export const schema = gql` email: String! name: String agencyId: Int - organizationId: Int! roleId: Int } @@ -35,7 +34,6 @@ export const schema = gql` email: String name: String agencyId: Int - organizationId: Int roleId: Int } diff --git a/api/types/graphql.d.ts b/api/types/graphql.d.ts index bca6af84..0666aac4 100644 --- a/api/types/graphql.d.ts +++ b/api/types/graphql.d.ts @@ -150,7 +150,6 @@ export type CreateUserInput = { agencyId?: InputMaybe email: Scalars['String'] name?: InputMaybe - organizationId: Scalars['Int'] roleId?: InputMaybe } @@ -385,6 +384,7 @@ export type Query = { uploads: Array user?: Maybe users: Array + usersByOrganization: Array } /** About the Redwood queries. */ @@ -559,7 +559,6 @@ export type UpdateUserInput = { agencyId?: InputMaybe email?: InputMaybe name?: InputMaybe - organizationId?: InputMaybe roleId?: InputMaybe } @@ -1736,7 +1735,7 @@ export type QueryResolvers< ParentType, ContextType > - usersByOrganization: OptArgsResolverFn< + usersByOrganization: Resolver< Array, ParentType, ContextType, diff --git a/web/src/components/User/UserForm/UserForm.tsx b/web/src/components/User/UserForm/UserForm.tsx index ac330740..69d65f26 100644 --- a/web/src/components/User/UserForm/UserForm.tsx +++ b/web/src/components/User/UserForm/UserForm.tsx @@ -43,12 +43,31 @@ const UserForm = (props: UserFormProps) => { error={error} className={hasErrors ? 'was-validated' : ''} > + {user && ( +
+ +
+ +
+
+ )} + {user && (
-
+
{ defaultValue={props.user?.name} className="form-control" errorClassName="form-control is-invalid" + validation={{ required: 'This field is required' }} />
@@ -109,7 +129,7 @@ const UserForm = (props: UserFormProps) => {
@@ -119,6 +139,7 @@ const UserForm = (props: UserFormProps) => { className="form-control" errorClassName="form-control is-invalid" emptyAs={'undefined'} + validation={{ required: 'This field is required' }} />
@@ -140,6 +161,7 @@ const UserForm = (props: UserFormProps) => { className="form-control" errorClassName="form-control is-invalid" emptyAs={'undefined'} + validation={{ required: 'This field is required' }} />
@@ -149,30 +171,6 @@ const UserForm = (props: UserFormProps) => { />
-
- - -
- -
- - -
-
diff --git a/web/types/graphql.d.ts b/web/types/graphql.d.ts index 25b892a6..156592e6 100644 --- a/web/types/graphql.d.ts +++ b/web/types/graphql.d.ts @@ -104,7 +104,6 @@ export type CreateUserInput = { agencyId?: InputMaybe email: Scalars['String'] name?: InputMaybe - organizationId: Scalars['Int'] roleId?: InputMaybe } @@ -514,7 +513,6 @@ export type UpdateUserInput = { agencyId?: InputMaybe email?: InputMaybe name?: InputMaybe - organizationId?: InputMaybe roleId?: InputMaybe }