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 | 1x 1x 15x 1x 22x 22x 22x 22x 22x 22x 16x 22x 22x 22x 22x 5x 20x 5x 15x 5x 22x 10x 22x 3x 19x 11x 11x 19x 1x | import { useEffect, useMemo, useState } from "react";
import { Box, Grid } from "@mui/material";
import GiveBaseModal from "@shared/modals/GiveBaseModal";
import GiveText from "@shared/Text/GiveText";
import { TProfileTab } from "./types";
import {
BellSimpleRingingIcon,
HandPalmIcon,
Icon,
ShieldPlusIcon,
UserCircleGearIcon,
XIcon,
} from "@phosphor-icons/react";
import ProfileModalSidebar from "./ProfileModalSidebar";
import GiveIconButton from "@shared/IconButton/GiveIconButton";
import { styled, useAppTheme } from "@theme/v2/Provider";
import AccountAccessibility from "../Accessibility/AccountAccessibility";
import AccountDetails from "../AccountDetails/AccountDetails";
import Security from "../Security/Security";
import GiveNotificationsCenter from "componentsV2/AccountProfile/NotificationCenter/GiveNotificationCenter";
import { useCustomThemeV2 } from "@theme/hooks/useCustomThemeV2";
import AccountProfileMobileDrawer from "./AccountProfileMobileDrawer";
import { useGetFeatureFlagValues } from "FeatureFlags/useGetFeatureFlagValues";
import NiceModal from "@ebay/nice-modal-react";
import { ProfileModalBody } from "@components/ProfileMenu/modals/ProfileModal";
import useNiceModal from "@common/Modal/ModalFactory/hooks/useNiceModal";
import ProfileModalActions from "./ProfileModalActions";
import { FormProvider } from "react-hook-form";
import { useAccountProfile } from "../hooks/useAccountProfile";
const ProfilePage = {
"Account Details": AccountDetails,
Security: Security,
Accessibility: AccountAccessibility,
Notifications: GiveNotificationsCenter,
};
type Props = {
initialTab?: TProfileTab;
goBack?: (event: React.MouseEvent<HTMLElement>) => void;
};
const NewAccountProfileModal = NiceModal.create((props: Props) => {
return <NewAccountProfileBody {...props} />;
});
const NewAccountProfileBody = ({ goBack, initialTab }: Props) => {
const { palette } = useAppTheme();
const { open, onClose } = useNiceModal();
const { isMobileView } = useCustomThemeV2();
const [sidebarList, setSidebarList] = useState(initialSidebarList);
const [isDisabled, setDisabled] = useState(false);
const activeTab = useMemo(
() => sidebarList.find((item) => item.active)?.tab || "Account Details",
[sidebarList],
);
const ActivePage = ProfilePage[activeTab];
const { form, handleSubmit } = useAccountProfile({ activeTab });
const { methods = {}, isDirty, isLoading } = form;
const handleSelectTab = (tab: TProfileTab) => {
const updatedTabs = sidebarList.map((item) => {
if (item.tab === tab)
return {
...item,
active: true,
};
return { ...item, active: false };
});
setSidebarList(updatedTabs);
};
useEffect(() => {
if (open) handleSelectTab(initialTab || "Account Details");
}, [open]);
if (isMobileView) {
return (
<AccountProfileMobileDrawer
sidebarList={sidebarList}
ProfilePage={ProfilePage}
openModal={open}
goBack={goBack}
initialTab={initialTab}
/>
);
}
return (
<StyledModal open={open} title="" width="800px" onClose={onClose}>
<FormProvider {...methods}>
<Box
component={activeTab === "Notifications" ? "div" : "form"}
onSubmit={
activeTab === "Notifications" ? null : (handleSubmit as any)
}
>
<Grid container>
<Grid item xs={3.5}>
<ProfileModalSidebar
sidebarList={sidebarList}
handleSelectTab={handleSelectTab}
/>
</Grid>
<Grid item xs={8.5} sx={{ background: palette.surface?.primary }}>
<HeaderContainer>
<GiveText variant="bodyM">{activeTab}</GiveText>
<GiveIconButton
Icon={XIcon}
color={palette.icon?.["icon-primary"]}
size="small"
variant="ghost"
onClick={onClose}
/>
</HeaderContainer>
<ActivePageContainer>
<ActivePage setDisabled={setDisabled} />
</ActivePageContainer>
<ProfileModalActions
isDirty={
isDirty || (!isDisabled && activeTab === "Notifications")
}
isDisabled={
(isDisabled && activeTab === "Security") || isLoading
}
form={
activeTab === "Notifications"
? "account-profile-form"
: undefined
}
/>
</Grid>
</Grid>
</Box>
</FormProvider>
</StyledModal>
);
};
const HeaderContainer = styled(Box)(({ theme }) => ({
display: "flex",
justifyContent: "space-between",
alignItems: "center",
padding: "16px 20px",
borderBottom: `1px solid ${theme.palette.border?.primary}`,
}));
const ActivePageContainer = styled(Box)(() => ({
padding: "32px 40px 40px 40px",
height: "65vh",
maxHeight: "65vh",
overflowY: "auto",
}));
const StyledModal = styled(GiveBaseModal)(({ theme }) => ({
"& .MuiDialogContent-root": {
padding: 0,
},
"& .MuiDialogTitle-root + .MuiDialogContent-root": {
padding: 0,
},
"& .MuiDialogTitle-root": {
display: "none",
},
"& .MuiDialogActions-root": {
display: "none",
},
"& .MuiDialog-paper": {
background: `${theme.palette.surface?.["secondary-transparent"]} !important`,
backdropFilter: "blur(8px)",
},
}));
const initialSidebarList = [
{ tab: "Account Details", icon: UserCircleGearIcon, active: true },
{ tab: "Security", icon: ShieldPlusIcon, active: false },
{ tab: "Accessibility", icon: HandPalmIcon, active: false },
{ tab: "Notifications", icon: BellSimpleRingingIcon, active: false },
] as { tab: TProfileTab; icon: Icon; active: boolean }[];
export default NewAccountProfileModal;
|