From 4bf4ac591d91f0b0f4bf4090ce641aa0c7239505 Mon Sep 17 00:00:00 2001 From: Gabriel Garcia Date: Fri, 19 Dec 2025 06:33:56 +0100 Subject: [PATCH 1/4] feat(termination): add offboarding validation and useGetOffboardings hook --- example/src/Termination.tsx | 47 ++++++++++++++++++++++++++++++------ src/flows/Termination/api.ts | 34 ++++++++++++++++++++++++++ src/index.tsx | 2 ++ 3 files changed, 75 insertions(+), 8 deletions(-) diff --git a/example/src/Termination.tsx b/example/src/Termination.tsx index 0365e208..9de5c2db 100644 --- a/example/src/Termination.tsx +++ b/example/src/Termination.tsx @@ -1,4 +1,8 @@ -import { TerminationFlow, zendeskArticles } from '@remoteoss/remote-flows'; +import { + TerminationFlow, + useGetOffboardings, + zendeskArticles, +} from '@remoteoss/remote-flows'; import type { TerminationRenderProps, TerminationFormValues, @@ -184,14 +188,28 @@ const TerminationRender = ({ ); }; -export const TerminationWithProps = ({ - employmentId, -}: { - employmentId: string; -}) => { - const proxyURL = window.location.origin; +const Termination = ({ employmentId }: { employmentId: string }) => { + const { data: offboardings, isLoading: isLoadingOffboardings } = + useGetOffboardings({ + params: { + employmentId: employmentId, + includeConfidential: true, + }, + options: { + enabled: !!employmentId, + }, + }); + + if (isLoadingOffboardings) { + return
Loading offboardings...
; + } + + if (offboardings?.total_count && offboardings?.total_count > 0) { + return
You have already submitted a termination requests
; + } + return ( - + <> + + ); +}; + +export const TerminationWithProps = ({ + employmentId, +}: { + employmentId: string; +}) => { + const proxyURL = window.location.origin; + return ( + + ); }; diff --git a/src/flows/Termination/api.ts b/src/flows/Termination/api.ts index d5e44b89..7f47d287 100644 --- a/src/flows/Termination/api.ts +++ b/src/flows/Termination/api.ts @@ -1,5 +1,6 @@ import { CreateOffboardingParams, + getIndexOffboarding, postCreateOffboarding, Timeoff, } from '@/src/client'; @@ -316,3 +317,36 @@ export const useTerminationSchema = ({ }, }); }; + +export const useGetOffboardings = ({ + params, + options, +}: { + params: { + employmentId: string; + includeConfidential: boolean; + }; + options?: { enabled: boolean }; +}) => { + const { client } = useClient(); + return useQuery({ + queryKey: [ + 'rmt-flows-get-offboardings', + params.employmentId, + params.includeConfidential, + ], + queryFn: () => { + return getIndexOffboarding({ + client: client as Client, + query: { + employment_id: params.employmentId, + include_confidential: params.includeConfidential ? 'true' : 'false', + }, + }); + }, + select: ({ data }) => { + return data?.data; + }, + enabled: options?.enabled, + }); +}; diff --git a/src/index.tsx b/src/index.tsx index a96e1bfd..ffda905f 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -33,6 +33,8 @@ export { TerminationDialogInfoContent, } from '@/src/flows/Termination'; +export { useGetOffboardings } from '@/src/flows/Termination/api'; + export type { TerminationFormValues, TerminationFlowProps, From 94f8f29afdd3d282614b1f929dccf1bf219c142d Mon Sep 17 00:00:00 2001 From: Gabriel Garcia Date: Fri, 19 Dec 2025 06:43:37 +0100 Subject: [PATCH 2/4] refactor(termination): add generic select support to useGetOffboardings hook --- example/src/Termination.tsx | 7 +++++-- src/flows/Termination/api.ts | 10 +++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/example/src/Termination.tsx b/example/src/Termination.tsx index 9de5c2db..f93cb9cd 100644 --- a/example/src/Termination.tsx +++ b/example/src/Termination.tsx @@ -189,7 +189,7 @@ const TerminationRender = ({ }; const Termination = ({ employmentId }: { employmentId: string }) => { - const { data: offboardings, isLoading: isLoadingOffboardings } = + const { data: totalOffboardings, isLoading: isLoadingOffboardings } = useGetOffboardings({ params: { employmentId: employmentId, @@ -197,6 +197,9 @@ const Termination = ({ employmentId }: { employmentId: string }) => { }, options: { enabled: !!employmentId, + select: (data) => { + return data?.total_count; + }, }, }); @@ -204,7 +207,7 @@ const Termination = ({ employmentId }: { employmentId: string }) => { return
Loading offboardings...
; } - if (offboardings?.total_count && offboardings?.total_count > 0) { + if (totalOffboardings && totalOffboardings > 0) { return
You have already submitted a termination requests
; } diff --git a/src/flows/Termination/api.ts b/src/flows/Termination/api.ts index 7f47d287..fae419cf 100644 --- a/src/flows/Termination/api.ts +++ b/src/flows/Termination/api.ts @@ -1,6 +1,7 @@ import { CreateOffboardingParams, getIndexOffboarding, + ListOffboardingResponse, postCreateOffboarding, Timeoff, } from '@/src/client'; @@ -318,7 +319,7 @@ export const useTerminationSchema = ({ }); }; -export const useGetOffboardings = ({ +export const useGetOffboardings = ({ params, options, }: { @@ -326,7 +327,10 @@ export const useGetOffboardings = ({ employmentId: string; includeConfidential: boolean; }; - options?: { enabled: boolean }; + options?: { + enabled: boolean; + select?: (data: ListOffboardingResponse['data']) => TData; + }; }) => { const { client } = useClient(); return useQuery({ @@ -345,7 +349,7 @@ export const useGetOffboardings = ({ }); }, select: ({ data }) => { - return data?.data; + return (options?.select?.(data?.data) ?? data?.data) as TData; }, enabled: options?.enabled, }); From 645c9f69cfce779b83bcd6a34e474a2cb49b369a Mon Sep 17 00:00:00 2001 From: Gabriel Garcia Date: Fri, 19 Dec 2025 06:47:47 +0100 Subject: [PATCH 3/4] refactor(termination-api): make offboarding query params optional and add JSDoc --- src/flows/Termination/api.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/flows/Termination/api.ts b/src/flows/Termination/api.ts index fae419cf..6c86a051 100644 --- a/src/flows/Termination/api.ts +++ b/src/flows/Termination/api.ts @@ -319,14 +319,22 @@ export const useTerminationSchema = ({ }); }; +/** + * Hook to retrieve list of offboardings or filter offboardings by employmentId. + * + * @param {Object} params - The parameters for the query. + * @param {string} [params.employmentId] - The ID of the employment to fetch offboardings for. + * @param {boolean} [params.includeConfidential] - Whether to include confidential offboardings in the response. + * @returns {TData} - The offboardings data. + */ export const useGetOffboardings = ({ params, options, }: { - params: { - employmentId: string; - includeConfidential: boolean; - }; + params: Partial<{ + employmentId?: string; + includeConfidential?: boolean; + }>; options?: { enabled: boolean; select?: (data: ListOffboardingResponse['data']) => TData; From acb5d838f113e2b6489cb3414c6a91facb1135ef Mon Sep 17 00:00:00 2001 From: Gabriel Garcia Date: Fri, 19 Dec 2025 06:55:49 +0100 Subject: [PATCH 4/4] optional params --- src/flows/Termination/api.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/flows/Termination/api.ts b/src/flows/Termination/api.ts index 6c86a051..781f6e67 100644 --- a/src/flows/Termination/api.ts +++ b/src/flows/Termination/api.ts @@ -335,10 +335,10 @@ export const useGetOffboardings = ({ employmentId?: string; includeConfidential?: boolean; }>; - options?: { - enabled: boolean; + options?: Partial<{ + enabled?: boolean; select?: (data: ListOffboardingResponse['data']) => TData; - }; + }>; }) => { const { client } = useClient(); return useQuery({