Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | 17x 52x 52x 52x 52x 52x 52x 52x 82x 52x 52x 52x 10x 52x 52x 19x 52x 10x 10x 52x 10x 10x 52x 52x 52x 52x 52x 9x 9x 52x 11x 2x 2x 9x 9x 52x 52x 39x 13x 13x 13x 17x 17x | import { useEffect, useState } from "react";
import { useDispatch, useSelector } from "react-redux";
import { setOnboardingScreen } from "@redux/slices/app";
import { checkPortals } from "@utils/routing";
import { useGetProfileStatus } from "./useGetProfileStatus";
import { ProfilePageContainer } from "@components/ProfilePage";
import { useGetMerchantById } from "@hooks/enterprise-api/account/useGetMerchants";
import { useLocation, useNavigate } from "react-router-dom";
import {
Background,
Card,
CardHeader,
ChecklistButton,
ChecklistContainer,
WelcomePageContainer,
} from "./WelcomePage.atoms";
import useMasqueradeReducer from "@hooks/Reducers/useMasqueradeReducer";
import { ENTERPRISE_PATHS, MERCHANT_PATHS } from "@routes/paths";
import LoadingSpinner from "@components/Snipper/LoadingSpinner";
import { OnboardingRedirectionEnum } from "@components/ProfilePage/utils";
import { useGetFeatureFlagValues } from "FeatureFlags/useGetFeatureFlagValues";
type TWelcomePageSection = "" | "profile";
export enum PageHash {
ONBOARDING = "#onboarding",
}
const WelcomePage = () => {
const navigate = useNavigate();
const [showInitialTitle, setShowInitialTitle] = useState(true);
const { masqueradeOffset } = useMasqueradeReducer();
const dispatch = useDispatch();
const location = useLocation();
const { isMerchantOnboardingModalEnabled } = useGetFeatureFlagValues();
const stateNextPage =
location?.state?.section ||
useSelector((state: any) => state.app.ui.onboarding);
const showNextPage =
stateNextPage === "init-profile" ? "profile" : stateNextPage;
const { isMerchantPortal, isEnterprisePortal } = checkPortals();
useEffect(() => {
Iif (isMerchantOnboardingModalEnabled && isMerchantPortal) {
navigate(`/merchant/${MERCHANT_PATHS.MANAGE_MONEY}`);
}
}, [isMerchantPortal, isMerchantOnboardingModalEnabled]);
const { data: merchant, isLoading: merchantLoading } = useGetMerchantById();
const setShowNextPage = (screen: TWelcomePageSection) =>
dispatch(setOnboardingScreen({ screen }));
useEffect(() => {
Iif (location.hash === PageHash.ONBOARDING) setShowNextPage("profile");
Iif (location.hash === `#${OnboardingRedirectionEnum.BUSINESS_DETAILS}`)
setShowNextPage("profile");
}, [location.hash]);
useEffect(() => {
return () => {
setShowNextPage("");
};
}, []);
const {
bankAccounts,
hasPrincipal,
pahStatus,
agreementStatus,
bankAccountStatus,
isProfileReady: isCompleted,
businessDetailsStatus,
isUnderReviewProfile,
legalEntity: { data: legalEntity },
allLoaded,
} = useGetProfileStatus(merchant);
const isFirstCampaignComplete = merchant?.hasCreatedProducts ?? false;
const isAccountCompleted =
isCompleted && (isMerchantPortal ? !isUnderReviewProfile : true);
const locationState = location?.state?.origin;
const handleClick = (show: TWelcomePageSection) => {
setShowNextPage(show);
Iif (!showInitialTitle) setShowInitialTitle(true);
};
useEffect(() => {
if (isAccountCompleted && locationState !== "card") {
Iif (isEnterprisePortal) {
navigate(`/provider/${ENTERPRISE_PATHS.TRANSACTIONS}`);
} else {
navigate(`/merchant/${MERCHANT_PATHS.MANAGE_MONEY}`);
}
} else Iif (locationState === "card") {
handleClick("profile");
} else {
handleClick("");
}
}, [isCompleted]);
const actions = [
{
label: "Complete your profile",
action: () => handleClick("profile"),
isCompleted: isCompleted,
isUnderReviewProfile: isUnderReviewProfile,
},
];
if ((!allLoaded || merchantLoading) && !showNextPage)
return <LoadingSpinner />;
Eif ((showInitialTitle && locationState !== "card") || !showNextPage) {
return (
<>
<Background page="welcome" fullscreen />
<WelcomePageContainer
masqueradeOffset={masqueradeOffset}
data-testid="welcome-page-container"
sx={{
...(!showNextPage ? "" : unmountedStyle),
}}
onAnimationEnd={() => {
if (showNextPage) setShowInitialTitle(false);
}}
>
<Card>
<CardHeader
completed={
isCompleted &&
(isMerchantPortal ? isFirstCampaignComplete : true)
}
/>
<ChecklistContainer>
{actions.map((item, index) => {
// if (item.hidden) return null;
return (
<ChecklistButton
label={item.label}
action={item.action}
isCompleted={item.isCompleted}
// disabled={item.disabled}
key={index}
isUnderReviewProfile={item?.isUnderReviewProfile}
/>
);
})}
</ChecklistContainer>
</Card>
</WelcomePageContainer>
</>
);
}
return (
<WelcomePageContainer
masqueradeOffset={masqueradeOffset}
sx={{
...(showNextPage ? mountedStyle : unmountedStyle),
justifyContent: "flex-start",
}}
>
{showNextPage === "profile" && (
<ProfilePageContainer
backToWelcomePage={() => {
setShowNextPage("");
setShowInitialTitle(true);
}}
legalEntity={legalEntity}
matchTaxID
hasPrincipal={hasPrincipal}
bankAccountStatus={bankAccountStatus}
msaStatus={agreementStatus}
bankAccountsList={bankAccounts.rows}
businessDetailsStatus={businessDetailsStatus}
pahStatus={pahStatus}
merchant={merchant}
/>
)}
</WelcomePageContainer>
);
};
const mountedStyle = { animation: "inAnimation 270ms ease-in" };
const unmountedStyle = {
animation: "outAnimation 270ms ease-out",
animationFillMode: "forwards",
};
export default WelcomePage;
|