From 29a6dfee89b5bd49c0d286eb7c3d5b6d01a0609f Mon Sep 17 00:00:00 2001 From: Keane Chan Date: Fri, 4 Nov 2022 18:00:34 +0800 Subject: [PATCH] [resumes][chore] locationId migration --- .../migration.sql | 13 +++++++++ apps/portal/prisma/schema.prisma | 4 ++- apps/portal/src/pages/resumes/submit.tsx | 27 ++++++++++--------- 3 files changed, 31 insertions(+), 13 deletions(-) create mode 100644 apps/portal/prisma/migrations/20221104095551_use_location_database_for_resumes/migration.sql diff --git a/apps/portal/prisma/migrations/20221104095551_use_location_database_for_resumes/migration.sql b/apps/portal/prisma/migrations/20221104095551_use_location_database_for_resumes/migration.sql new file mode 100644 index 00000000..35991ddb --- /dev/null +++ b/apps/portal/prisma/migrations/20221104095551_use_location_database_for_resumes/migration.sql @@ -0,0 +1,13 @@ +/* + Warnings: + + - You are about to drop the column `location` on the `ResumesResume` table. All the data in the column will be lost. + - Added the required column `locationId` to the `ResumesResume` table without a default value. This is not possible if the table is not empty. + +*/ +-- AlterTable +ALTER TABLE "ResumesResume" DROP COLUMN "location", +ADD COLUMN "locationId" TEXT NOT NULL; + +-- AddForeignKey +ALTER TABLE "ResumesResume" ADD CONSTRAINT "ResumesResume_locationId_fkey" FOREIGN KEY ("locationId") REFERENCES "Country"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/apps/portal/prisma/schema.prisma b/apps/portal/prisma/schema.prisma index 662a321c..77a8d44b 100644 --- a/apps/portal/prisma/schema.prisma +++ b/apps/portal/prisma/schema.prisma @@ -112,6 +112,7 @@ model Country { code String @unique states State[] questionsQuestionEncounters QuestionsQuestionEncounter[] + ResumesResume ResumesResume[] } model State { @@ -148,13 +149,14 @@ model ResumesResume { // TODO: Update role, experience, location to use Enums role String @db.Text experience String @db.Text - location String @db.Text + locationId String url String additionalInfo String? @db.Text isResolved Boolean @default(false) createdAt DateTime @default(now()) updatedAt DateTime @updatedAt user User @relation(fields: [userId], references: [id], onDelete: Cascade) + location Country @relation(fields: [locationId], references: [id], onDelete: Cascade) stars ResumesStar[] comments ResumesComment[] } diff --git a/apps/portal/src/pages/resumes/submit.tsx b/apps/portal/src/pages/resumes/submit.tsx index 8370e1ac..f025f325 100644 --- a/apps/portal/src/pages/resumes/submit.tsx +++ b/apps/portal/src/pages/resumes/submit.tsx @@ -20,10 +20,10 @@ import { } from '@tih/ui'; import { useGoogleAnalytics } from '~/components/global/GoogleAnalytics'; -import RoleTypeahead from '~/components/questions/typeahead/RoleTypeahead'; +import ResumeLocationTypeahead from '~/components/resumes/shared/ResumeLocationTypeahead'; +import ResumeRoleTypeahead from '~/components/resumes/shared/ResumeRoleTypeahead'; import ResumeSubmissionGuidelines from '~/components/resumes/submit-form/ResumeSubmissionGuidelines'; import Container from '~/components/shared/Container'; -import CountriesTypeahead from '~/components/shared/CountriesTypeahead'; import loginPageHref from '~/components/shared/loginPageHref'; import { RESUME_STORAGE_KEY } from '~/constants/file-storage-keys'; @@ -43,7 +43,7 @@ type IFormInput = { experience: string; file: File; isChecked: boolean; - location: string; + locationId: string; role: string; title: string; }; @@ -97,7 +97,7 @@ export default function SubmitResumeForm({ additionalInfo: '', experience: '', isChecked: false, - location: '', + locationId: '', role: '', title: '', ...initFormDetails, @@ -161,7 +161,7 @@ export default function SubmitResumeForm({ additionalInfo: data.additionalInfo, experience: data.experience, id: initFormDetails?.resumeId, - location: data.location, + locationId: data.locationId, role: data.role, title: data.title, url: fileUrl, @@ -307,12 +307,15 @@ export default function SubmitResumeForm({ control={control} name="role" render={() => ( - - onValueChange('role', option.value) - } + onSelect={(option) => { + if (option == null) { + return; + } + onValueChange('role', option.value); + }} /> )} rules={{ required: true }} @@ -329,16 +332,16 @@ export default function SubmitResumeForm({ ( - { if (option == null) { return; } - onValueChange('location', option.value); + onValueChange('locationId', option.value); }} /> )}