-
Notifications
You must be signed in to change notification settings - Fork 0
feat(onboarding): wire onBlur events to job title eligibility check #1406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
e872b0b
33aabca
330242b
edadc3c
382c58f
7686a5e
38681bb
f641052
6b6034b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,4 +19,4 @@ CLAUDE.local.md | |
| coverage | ||
| example/public/ | ||
| out | ||
| example/tsconfig.e2e.tsbuildinfo | ||
| example/tsconfig.e2e.tsbuildinfo | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| import { ValidationResult } from '@remoteoss/remote-json-schema-form-kit'; | ||
| import { useQuery, useQueryClient } from '@tanstack/react-query'; | ||
| import equal from 'fast-deep-equal'; | ||
| import { useRef, useState } from 'react'; | ||
| import { FieldValues } from 'react-hook-form'; | ||
| import { CreateJobTitleEligibilityCheckParams } from '@/src/client'; | ||
| import { Client } from '@/src/client/client'; | ||
| import { useClient } from '@/src/context'; | ||
| import { jobTitleEligibilityCheckOptions } from '@/src/flows/Onboarding/api'; | ||
| import { | ||
| getJobTitleEligibilityParams, | ||
| StepKeys, | ||
| } from '@/src/flows/Onboarding/utils'; | ||
| import { JSFFields } from '@/src/types/remoteFlows'; | ||
|
|
||
| /** | ||
| * Owns the state and query for the job title eligibility check. | ||
| */ | ||
| export const useJobTitleEligibilityState = ({ | ||
| employmentId, | ||
| enabled, | ||
| currentStepName, | ||
| }: { | ||
| employmentId: string | undefined; | ||
| enabled: boolean; | ||
| currentStepName: StepKeys; | ||
| }) => { | ||
| const { client } = useClient(); | ||
| const [params, setParamsState] = | ||
| useState<CreateJobTitleEligibilityCheckParams | null>(null); | ||
| const paramsRef = useRef(params); | ||
|
|
||
| const setParams = (next: CreateJobTitleEligibilityCheckParams | null) => { | ||
| paramsRef.current = next; | ||
| setParamsState(next); | ||
| }; | ||
|
|
||
| const getOptions = (checkParams: CreateJobTitleEligibilityCheckParams) => | ||
| jobTitleEligibilityCheckOptions( | ||
| client as Client, | ||
| employmentId as string, | ||
| checkParams, | ||
| ); | ||
|
|
||
| const query = useQuery({ | ||
| ...getOptions(params ?? {}), | ||
| enabled: Boolean( | ||
| enabled && | ||
| employmentId && | ||
| currentStepName === 'contract_details' && | ||
| params, | ||
| ), | ||
| }); | ||
|
|
||
| return { | ||
| paramsRef, | ||
| setParams, | ||
| getOptions, | ||
| query, | ||
| }; | ||
| }; | ||
|
|
||
| export const useJobTitleEligibilityCheck = ({ | ||
| enabled, | ||
| employmentId, | ||
| currentStepName, | ||
| contractDetailsFields, | ||
| fallbackJobTitle, | ||
| submittedJobTitle, | ||
| parseFormValues, | ||
| handleValidation, | ||
| }: { | ||
| enabled: boolean; | ||
| employmentId: string | undefined; | ||
| currentStepName: StepKeys; | ||
| contractDetailsFields: JSFFields; | ||
| fallbackJobTitle: string | undefined; | ||
| parseFormValues: (values: FieldValues) => Promise<Record<string, unknown>>; | ||
| handleValidation: ( | ||
| values: FieldValues, | ||
| ) => Promise<ValidationResult | null | undefined>; | ||
| submittedJobTitle: string | undefined; | ||
| }) => { | ||
| const queryClient = useQueryClient(); | ||
| const { paramsRef, setParams, getOptions, query } = | ||
| useJobTitleEligibilityState({ | ||
| employmentId, | ||
| enabled, | ||
| currentStepName, | ||
| }); | ||
|
|
||
| const jobTitle = submittedJobTitle ?? fallbackJobTitle; | ||
|
|
||
| const check = async (values: FieldValues) => { | ||
| if (!enabled || !employmentId || currentStepName !== 'contract_details') { | ||
| return; | ||
| } | ||
| const validation = await handleValidation(values); | ||
| const parsedValues = await parseFormValues(values); | ||
| const nextParams = getJobTitleEligibilityParams( | ||
| contractDetailsFields, | ||
| parsedValues, | ||
| validation?.formErrors, | ||
| jobTitle, | ||
| ); | ||
| const paramsChanged = !equal(paramsRef.current, nextParams); | ||
| if (paramsChanged) { | ||
| setParams(nextParams); | ||
| } | ||
| if (nextParams && paramsChanged) { | ||
| await queryClient | ||
| .query(getOptions(nextParams)) | ||
| .catch(() => | ||
| console.error('Failed to fetch job title eligibility check'), | ||
|
cursor[bot] marked this conversation as resolved.
|
||
| ); | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Failed checks skip later retriesMedium Severity
Reviewed by Cursor Bugbot for commit 38681bb. Configure here.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixing it in #1408 |
||
| }; | ||
|
|
||
| return { | ||
| isFetching: query.isFetching, | ||
| check, | ||
| }; | ||
| }; | ||
|
gabrielseco marked this conversation as resolved.
|
||


Uh oh!
There was an error while loading. Please reload this page.