Skip to content

Commit

Permalink
fix: hotfix for career page language selection and profile registrati…
Browse files Browse the repository at this point in the history
…on (#501)

* fix: adding unblur message and fixing language selection

* fix: fixing user preregister profile

* feat: redirect to application link
  • Loading branch information
JasonNotJson authored Nov 17, 2023
1 parent fcee7bc commit a2b2e5b
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 11 deletions.
4 changes: 4 additions & 0 deletions apps/career/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const PageRoutes = ({
profile,
setProfile,
isRegistered,
setIsRegistered,
onJobApplied,
}: CareerComponentProps) => {
return (
Expand All @@ -38,6 +39,7 @@ const PageRoutes = ({
profile={profile}
setProfile={setProfile}
isRegistered={isRegistered}
setIsRegistered={setIsRegistered}
/>
}
path="/"
Expand Down Expand Up @@ -168,7 +170,9 @@ const InnerApp = () => {
profile={profile}
setProfile={setProfile}
isRegistered={isRegistered}
setIsRegistered={setIsRegistered}
onJobApplied={handleJobApplied}
setIsRegsitered={setIsRegistered}
/>
</div>
</div>
Expand Down
9 changes: 8 additions & 1 deletion apps/career/src/components/common/AgreeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ const AgreeModal: React.FC<AgreeModalProps> = ({
}) => {
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()
Expand Down
8 changes: 7 additions & 1 deletion apps/career/src/components/joblist/Joblist.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const Joblist: React.FC<CareerComponentProps> = ({
profile,
setProfile,
isRegistered,
setIsRegistered,
}) => {
const [isSignInModalOpen, setSignInModalOpen] = useState(false)
const [isLoggedIn, setIsLoggedIn] = useState(false)
Expand Down Expand Up @@ -68,7 +69,12 @@ const Joblist: React.FC<CareerComponentProps> = ({
setProfile={setProfile}
/>
) : (
<PreRegisterProfile profile={profile} setProfile={setProfile} />
<PreRegisterProfile
isRegistered={isRegistered}
profile={profile}
setIsRegistered={setIsRegistered}
setProfile={setProfile}
/>
)}
</div>
</div>
Expand Down
6 changes: 6 additions & 0 deletions apps/career/src/components/joblist/PreRegisterProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import CareerComponentProps from "@app/types/careerComponentProps"
import ProfileComponentProps from "@app/types/profileComponentProps"

const PreRegisterProfile: React.FC<ProfileComponentProps> = ({
isRegistered,
setIsRegistered,
profile,
setProfile,
}) => {
Expand All @@ -26,6 +28,9 @@ const PreRegisterProfile: React.FC<ProfileComponentProps> = ({
</div>
</div>
<div className="p-4">
<p className="font-bold leading-relaxed">
Register profile to unblur detail!
</p>
<p className="leading-relaxed">
Please register your user profile to apply for WasedaTime Careers. The
data collected is isolated and will only be used in the Careers page.
Expand All @@ -45,6 +50,7 @@ const PreRegisterProfile: React.FC<ProfileComponentProps> = ({
profile={profile}
setProfile={setProfile}
closeModal={toggleModal}
setIsRegistered={setIsRegistered}
/>
)}
</div>
Expand Down
27 changes: 19 additions & 8 deletions apps/career/src/components/joblist/ProfileModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const ProfileModal: React.FC<ProfileModalProps> = ({
setProfile,
closeModal,
isRegistered,
setIsRegistered,
}) => {
const [expandSchool, setExpandSchool] = useState(false)
const [userToken, setUserToken] = useState("")
Expand Down Expand Up @@ -69,7 +70,9 @@ const ProfileModal: React.FC<ProfileModalProps> = ({

// 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
Expand Down Expand Up @@ -125,15 +128,23 @@ const ProfileModal: React.FC<ProfileModalProps> = ({
}
}

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 (
<div className="fixed inset-0 z-[1000] h-full w-full overflow-y-auto bg-gray-600 bg-opacity-50">
<div className="flex h-full items-center justify-center">
Expand Down
1 change: 1 addition & 0 deletions apps/career/src/types/careerComponentProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ type CareerComponentProps = {
jobData: JobProps[]
profile: UserProfile
setProfile?: React.Dispatch<React.SetStateAction<UserProfile>>
setIsRegistered?: React.Dispatch<React.SetStateAction<boolean>>
isRegistered?: boolean
onJobApplied?: (jobId: string) => void
}
Expand Down
3 changes: 2 additions & 1 deletion apps/career/src/types/profileComponentProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import UserProfile from "./userProfile"
export interface ProfileComponentProps {
profile: UserProfile
setProfile: React.Dispatch<React.SetStateAction<UserProfile>>
isRegistered?: boolean // Include only if needed in both components
isRegistered?: boolean
setIsRegistered?: React.Dispatch<React.SetStateAction<boolean>>
}

export default ProfileComponentProps

0 comments on commit a2b2e5b

Please sign in to comment.