From a2b2e5b732a6d951ed9162534b1e486e42ae4976 Mon Sep 17 00:00:00 2001 From: Jason Park <93040528+JasonNotJson@users.noreply.github.com> Date: Fri, 17 Nov 2023 19:49:26 +0900 Subject: [PATCH] fix: hotfix for career page language selection and profile registration (#501) * fix: adding unblur message and fixing language selection * fix: fixing user preregister profile * feat: redirect to application link --- apps/career/src/App.tsx | 4 +++ .../src/components/common/AgreeModal.tsx | 9 ++++++- .../career/src/components/joblist/Joblist.tsx | 8 +++++- .../components/joblist/PreRegisterProfile.tsx | 6 +++++ .../src/components/joblist/ProfileModal.tsx | 27 +++++++++++++------ apps/career/src/types/careerComponentProps.ts | 1 + .../career/src/types/profileComponentProps.ts | 3 ++- 7 files changed, 47 insertions(+), 11 deletions(-) diff --git a/apps/career/src/App.tsx b/apps/career/src/App.tsx index 06f33dcc..655bf4ab 100644 --- a/apps/career/src/App.tsx +++ b/apps/career/src/App.tsx @@ -27,6 +27,7 @@ const PageRoutes = ({ profile, setProfile, isRegistered, + setIsRegistered, onJobApplied, }: CareerComponentProps) => { return ( @@ -38,6 +39,7 @@ const PageRoutes = ({ profile={profile} setProfile={setProfile} isRegistered={isRegistered} + setIsRegistered={setIsRegistered} /> } path="/" @@ -168,7 +170,9 @@ const InnerApp = () => { profile={profile} setProfile={setProfile} isRegistered={isRegistered} + setIsRegistered={setIsRegistered} onJobApplied={handleJobApplied} + setIsRegsitered={setIsRegistered} /> diff --git a/apps/career/src/components/common/AgreeModal.tsx b/apps/career/src/components/common/AgreeModal.tsx index 6f8b81ad..47d25692 100644 --- a/apps/career/src/components/common/AgreeModal.tsx +++ b/apps/career/src/components/common/AgreeModal.tsx @@ -20,7 +20,14 @@ const AgreeModal: React.FC = ({ }) => { const handleAgree = async () => { try { - const idToken = await getIdToken() // Correctly awaiting the Promise + // Check if job.apply is a URL and redirect if so + if (job.apply) { + window.open(job.apply, "_blank") // Open the URL in a new tab + onAgree() // Optionally call onAgree if needed after redirection + return // Return early to avoid executing the rest of the function + } + + const idToken = await getIdToken() // Continue with existing logic if job.apply is not a URL if (idToken) { await postApplication(profile, job, idToken) onAgree() diff --git a/apps/career/src/components/joblist/Joblist.tsx b/apps/career/src/components/joblist/Joblist.tsx index 3f1ba9f2..c10486e7 100644 --- a/apps/career/src/components/joblist/Joblist.tsx +++ b/apps/career/src/components/joblist/Joblist.tsx @@ -13,6 +13,7 @@ const Joblist: React.FC = ({ profile, setProfile, isRegistered, + setIsRegistered, }) => { const [isSignInModalOpen, setSignInModalOpen] = useState(false) const [isLoggedIn, setIsLoggedIn] = useState(false) @@ -68,7 +69,12 @@ const Joblist: React.FC = ({ setProfile={setProfile} /> ) : ( - + )} diff --git a/apps/career/src/components/joblist/PreRegisterProfile.tsx b/apps/career/src/components/joblist/PreRegisterProfile.tsx index 4ef9abe7..2b9c229a 100644 --- a/apps/career/src/components/joblist/PreRegisterProfile.tsx +++ b/apps/career/src/components/joblist/PreRegisterProfile.tsx @@ -5,6 +5,8 @@ import CareerComponentProps from "@app/types/careerComponentProps" import ProfileComponentProps from "@app/types/profileComponentProps" const PreRegisterProfile: React.FC = ({ + isRegistered, + setIsRegistered, profile, setProfile, }) => { @@ -26,6 +28,9 @@ const PreRegisterProfile: React.FC = ({
+

+ Register profile to unblur detail! +

Please register your user profile to apply for WasedaTime Careers. The data collected is isolated and will only be used in the Careers page. @@ -45,6 +50,7 @@ const PreRegisterProfile: React.FC = ({ profile={profile} setProfile={setProfile} closeModal={toggleModal} + setIsRegistered={setIsRegistered} /> )}

diff --git a/apps/career/src/components/joblist/ProfileModal.tsx b/apps/career/src/components/joblist/ProfileModal.tsx index 14869ba7..e771dc2f 100644 --- a/apps/career/src/components/joblist/ProfileModal.tsx +++ b/apps/career/src/components/joblist/ProfileModal.tsx @@ -25,6 +25,7 @@ const ProfileModal: React.FC = ({ setProfile, closeModal, isRegistered, + setIsRegistered, }) => { const [expandSchool, setExpandSchool] = useState(false) const [userToken, setUserToken] = useState("") @@ -69,7 +70,9 @@ const ProfileModal: React.FC = ({ // Handling language and level dropdowns if (name.startsWith("language") || name.startsWith("Level")) { - const index = name.endsWith("2") ? 1 : 0 // Determine the index based on the dropdown name + // Extract the number from the name to determine the index + const indexMatch = name.match(/\d+/) + const index = indexMatch ? parseInt(indexMatch[0], 10) - 1 : 0 const key = name.startsWith("language") ? "language" : "level" // Update the specific language or level @@ -125,15 +128,23 @@ const ProfileModal: React.FC = ({ } } - const handleSubmit = () => { - if (isRegistered) { - patchProfile(profile) - } else { - postProfile(profile) + const handleSubmit = async () => { + try { + if (isRegistered) { + await patchProfile(profile) + } else { + await postProfile(profile) + if (setIsRegistered) { + setIsRegistered(true) + } + } + } catch (error) { + console.error("Error in submitting profile:", error) + } finally { + closeModal() } - - closeModal() } + return (
diff --git a/apps/career/src/types/careerComponentProps.ts b/apps/career/src/types/careerComponentProps.ts index 5e7fcb03..5a97662b 100644 --- a/apps/career/src/types/careerComponentProps.ts +++ b/apps/career/src/types/careerComponentProps.ts @@ -5,6 +5,7 @@ type CareerComponentProps = { jobData: JobProps[] profile: UserProfile setProfile?: React.Dispatch> + setIsRegistered?: React.Dispatch> isRegistered?: boolean onJobApplied?: (jobId: string) => void } diff --git a/apps/career/src/types/profileComponentProps.ts b/apps/career/src/types/profileComponentProps.ts index 4b386224..d7fd0bfb 100644 --- a/apps/career/src/types/profileComponentProps.ts +++ b/apps/career/src/types/profileComponentProps.ts @@ -3,7 +3,8 @@ import UserProfile from "./userProfile" export interface ProfileComponentProps { profile: UserProfile setProfile: React.Dispatch> - isRegistered?: boolean // Include only if needed in both components + isRegistered?: boolean + setIsRegistered?: React.Dispatch> } export default ProfileComponentProps