Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 42 additions & 8 deletions example/src/Termination.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { TerminationFlow, zendeskArticles } from '@remoteoss/remote-flows';
import {
TerminationFlow,
useGetOffboardings,
zendeskArticles,
} from '@remoteoss/remote-flows';
import type {
TerminationRenderProps,
TerminationFormValues,
Expand Down Expand Up @@ -184,14 +188,31 @@ const TerminationRender = ({
);
};

export const TerminationWithProps = ({
employmentId,
}: {
employmentId: string;
}) => {
const proxyURL = window.location.origin;
const Termination = ({ employmentId }: { employmentId: string }) => {
const { data: totalOffboardings, isLoading: isLoadingOffboardings } =
useGetOffboardings({
params: {
employmentId: employmentId,
includeConfidential: true,
},
options: {
enabled: !!employmentId,
select: (data) => {
return data?.total_count;
},
},
});

if (isLoadingOffboardings) {
return <div>Loading offboardings...</div>;
}

if (totalOffboardings && totalOffboardings > 0) {
return <div>You have already submitted a termination requests </div>;
}

return (
<RemoteFlows proxy={{ url: proxyURL }} authType='company-manager'>
<>
<TerminationFlow
employmentId={employmentId}
render={TerminationRender}
Expand Down Expand Up @@ -223,6 +244,19 @@ export const TerminationWithProps = ({
}}
/>
<OffboardingRequestModal employee={{ name: 'Ken' }} />
</>
);
};

export const TerminationWithProps = ({
employmentId,
}: {
employmentId: string;
}) => {
const proxyURL = window.location.origin;
return (
<RemoteFlows proxy={{ url: proxyURL }} authType='company-manager'>
<Termination employmentId={employmentId} />
</RemoteFlows>
);
};
Expand Down
46 changes: 46 additions & 0 deletions src/flows/Termination/api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {
CreateOffboardingParams,
getIndexOffboarding,
ListOffboardingResponse,
postCreateOffboarding,
Timeoff,
} from '@/src/client';
Expand Down Expand Up @@ -316,3 +318,47 @@ 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 = <TData = ListOffboardingResponse['data']>({
params,
options,
}: {
params: Partial<{
employmentId?: string;
includeConfidential?: boolean;
}>;
options?: Partial<{
enabled?: boolean;
select?: (data: ListOffboardingResponse['data']) => TData;
}>;
}) => {
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 (options?.select?.(data?.data) ?? data?.data) as TData;
},
enabled: options?.enabled,
});
};
2 changes: 2 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export {
TerminationDialogInfoContent,
} from '@/src/flows/Termination';

export { useGetOffboardings } from '@/src/flows/Termination/api';

export type {
TerminationFormValues,
TerminationFlowProps,
Expand Down
Loading