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 | 1x 3x 3x 3x 3x 3x 3x 3x 1x 3x 3x 2x 3x 12x 1x 1x 1x 1x 4x | import { Box, Stack } from "@mui/material";
import { useEffect, useMemo, useState } from "react";
import { TProfileModalPage, TProfileTab } from "./types";
import { CaretLeftIcon, Icon } from "@phosphor-icons/react";
import GiveBaseModal from "@shared/modals/GiveBaseModal";
import { styled, useAppTheme } from "@theme/v2/Provider";
import ProfileModalHeader from "./ProfileModalHeader";
import GiveText from "@shared/Text/GiveText";
import GiveButton from "@shared/Button/GiveButton";
import GiveIconButton from "@shared/IconButton/GiveIconButton";
import ProfileModalActions from "./ProfileModalActions";
import { LOGOUT_MODAL } from "modals/modal_names";
import NiceModal from "@ebay/nice-modal-react";
import { FormProvider } from "react-hook-form";
import { useAccountProfile } from "../hooks/useAccountProfile";
import useNiceModal from "@common/Modal/ModalFactory/hooks/useNiceModal";
type Props = {
sidebarList: { tab: TProfileTab; icon: Icon; active: boolean }[];
ProfilePage: TProfileModalPage;
openModal: boolean;
goBack?: (event: React.MouseEvent<HTMLElement>) => void;
initialTab?: TProfileTab
};
const AccountProfileMobileDrawer = ({
sidebarList,
ProfilePage,
openModal,
goBack,
initialTab
}: Props) => {
const [tab, setTab] = useState<TProfileTab | null>(null);
const [isDisabled, setDisabled] = useState(false);
const { open, onClose } = useNiceModal();
const ActivePage = tab ? ProfilePage[tab] : null;
const { form, handleSubmit } = useAccountProfile({ activeTab: tab || "" });
const { methods = {}, isDirty, isLoading } = form;
const modalHeight = useMemo(() => {
Eif (!tab) return "35%";
if (tab === "Accessibility") return "62%";
return undefined;
}, [tab]);
const handleBack = (e: React.MouseEvent<HTMLElement>) => {
if (goBack) goBack(e);
onClose();
};
useEffect(() => {
if(open) setTab(initialTab || null)
}, [open])
return (
<GiveBaseModal
open={openModal}
title=""
width="800px"
onClose={onClose}
sx={modalStyles}
height={modalHeight}
>
{!tab && (
<Stack spacing={2} padding="20px 8px 20px 8px">
<TabHeader title="Edit Profile" handleBack={handleBack} />
<Stack spacing={0.5}>
{sidebarList.map(({ icon: Icon, tab }) => (
<Tab key={tab} onClick={() => setTab(tab)}>
<GiveText variant="bodyS">{tab}</GiveText>
<Icon size={20} />
</Tab>
))}
</Stack>
</Stack>
)}
{tab && ActivePage && (
<FormProvider {...methods}>
<Box
display="flex"
flexDirection="column"
height="100%"
component={tab === "Notifications" ? "div" : "form"}
onSubmit={tab === "Notifications" ? null : (handleSubmit as any)}
>
<TabHeader title={tab} handleBack={() => setTab(null)} />
<Box padding="0 20px 20px 20px" flexGrow={1}>
<ActivePage setDisabled={setDisabled} />
</Box>
<ProfileModalActions
isDirty={isDirty || (!isDisabled && tab === "Notifications")}
isDisabled={(isDisabled && tab === "Security") || isLoading}
form={
tab === "Notifications" ? "account-profile-form" : undefined
}
/>
</Box>
</FormProvider>
)}
</GiveBaseModal>
);
};
const modalStyles = {
"& .MuiDialogContent-root": {
padding: 0,
height: "80vh",
},
"& .MuiDialogTitle-root + .MuiDialogContent-root": {
padding: 0,
},
"& .MuiDialogTitle-root": {
display: "none",
},
"& .MuiDialogActions-root": {
display: "none",
},
};
type TabHeaderProps = {
title: string;
handleBack: (e: React.MouseEvent<HTMLElement>) => void;
};
const TabHeader = ({ title, handleBack }: TabHeaderProps) => {
const { palette } = useAppTheme();
return (
<Stack
height="42px"
direction="row"
gap={1}
alignItems="center"
justifyContent="space-between"
paddingX="20px"
mb={2}
mt={3}
>
<GiveIconButton
Icon={CaretLeftIcon}
color={palette.icon?.["icon-primary"]}
size="small"
variant="ghost"
onClick={handleBack}
sx={{
backgroundColor: palette.primitive?.neutral[5],
borderRadius: "50%",
}}
/>
<GiveText variant="bodyS">{title}</GiveText>
<Box />
</Stack>
);
};
const Tab = styled(Box)(() => ({
padding: "8px 8px 8px 12px",
display: "flex",
alignItems: "center",
justifyContent: "space-between",
}));
export default AccountProfileMobileDrawer;
|