Skip to content

Commit

Permalink
feat: reworked back to portal button logic (#2375)
Browse files Browse the repository at this point in the history
Co-authored-by: Alon Peretz <[email protected]>
  • Loading branch information
chesterkmr and alonp99 authored May 19, 2024
1 parent a654561 commit c575956
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
8 changes: 5 additions & 3 deletions apps/kyb-app/src/components/layouts/AppShell/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const Navigation = () => {
const { stateApi } = useStateManagerContext();
const { currentPage } = usePageResolverContext();
const { customer } = useCustomer();
const exitFromApp = useAppExit();
const { exit, isExitAvailable } = useAppExit();

const isFirstStep = currentPage?.number === 1;
const isDisabled = state.isLoading;
Expand All @@ -26,9 +26,11 @@ export const Navigation = () => {
return;
}

exitFromApp();
exit();
return;
}, [stateApi, exitFromApp]);
}, [stateApi, exit]);

if (isFirstStep && !isExitAvailable) return null;

return (
<button
Expand Down
6 changes: 5 additions & 1 deletion apps/kyb-app/src/hooks/useAppExit/useAppExit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@ export const useAppExit = () => {
}
}, [trackExit, customer]);

return exit;
return {
exit,
isExitAvailable:
uiSchema?.config?.kybOnExitAction === 'send-event' ? true : !!customer?.websiteUrl,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Button, Card } from '@ballerine/ui';
export const Approved = withSessionProtected(() => {
const { t } = useTranslation();
const { customer } = useCustomer();
const exitFromApp = useAppExit();
const { exit, isExitAvailable } = useAppExit();

return (
<div className="flex h-full items-center justify-center">
Expand All @@ -29,9 +29,9 @@ export const Approved = withSessionProtected(() => {
{t('approved.content', { companyName: customer?.displayName })}
</p>
</div>
{customer && (
{customer && isExitAvailable && (
<div className="flex justify-center">
<Button variant="secondary" onClick={exitFromApp}>
<Button variant="secondary" onClick={exit}>
{t('backToPortal', { companyName: customer.displayName })}
</Button>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const Success = withSessionProtected(() => {
const { t } = useTranslation();
const { customer } = useCustomer();

const exitFromApp = useAppExit();
const { exit, isExitAvailable } = useAppExit();

return (
<div className="flex h-full items-center justify-center">
Expand All @@ -29,9 +29,9 @@ export const Success = withSessionProtected(() => {
{t('success.content')}
</h2>
</div>
{customer?.displayName && (
{customer?.displayName && isExitAvailable && (
<div className="flex justify-center">
<Button variant="secondary" onClick={exitFromApp}>
<Button variant="secondary" onClick={exit}>
{t('backToPortal', { companyName: customer.displayName })}
</Button>
</div>
Expand Down

0 comments on commit c575956

Please sign in to comment.