2024-02-19 20:21:17 +00:00
|
|
|
|
import { useEffect, useState } from "react"
|
2023-11-05 23:33:40 +00:00
|
|
|
|
import { Box, Button, SxProps, Theme, Typography, useMediaQuery, useTheme } from "@mui/material"
|
|
|
|
|
import InputTextfield from "@components/InputTextfield"
|
|
|
|
|
import PasswordInput from "@components/passwordInput"
|
|
|
|
|
import UserFields from "./UserFields"
|
|
|
|
|
import SectionWrapper from "@components/SectionWrapper"
|
|
|
|
|
import { openDocumentsDialog, sendUserData, setSettingsField, useUserStore } from "@root/stores/user"
|
|
|
|
|
import UnderlinedButtonWithIcon from "@root/components/UnderlinedButtonWithIcon"
|
|
|
|
|
import UploadIcon from "@root/components/icons/UploadIcon"
|
|
|
|
|
import DocumentsDialog from "./DocumentsDialog/DocumentsDialog"
|
|
|
|
|
import EyeIcon from "@root/components/icons/EyeIcon"
|
|
|
|
|
import { cardShadow } from "@root/utils/theme"
|
|
|
|
|
import { getMessageFromFetchError } from "@frontend/kitui"
|
|
|
|
|
import { enqueueSnackbar } from "notistack"
|
|
|
|
|
import { VerificationStatus } from "@root/model/account"
|
|
|
|
|
import { verify } from "./helper"
|
|
|
|
|
import { withErrorBoundary } from "react-error-boundary"
|
|
|
|
|
import { handleComponentError } from "@root/utils/handleComponentError"
|
2024-02-19 20:21:17 +00:00
|
|
|
|
import { OnChangeLoginPassword } from "./onChangeLoginPassword"
|
2023-03-19 11:26:09 +00:00
|
|
|
|
|
2023-10-27 17:38:06 +00:00
|
|
|
|
function AccountSettings() {
|
2023-11-05 23:33:40 +00:00
|
|
|
|
const theme = useTheme()
|
|
|
|
|
const upMd = useMediaQuery(theme.breakpoints.up("md"))
|
|
|
|
|
const upSm = useMediaQuery(theme.breakpoints.up("sm"))
|
|
|
|
|
const isTablet = useMediaQuery(theme.breakpoints.down(1000))
|
|
|
|
|
const isMobile = useMediaQuery(theme.breakpoints.down(600))
|
2023-06-02 08:22:14 +00:00
|
|
|
|
|
2024-02-19 20:21:17 +00:00
|
|
|
|
const { settingsFields, user } = useUserStore((state) => state)
|
2023-11-05 23:33:40 +00:00
|
|
|
|
const verificationStatus = useUserStore((state) => state.verificationStatus)
|
|
|
|
|
const verificationType = useUserStore((state) => state.verificationType)
|
|
|
|
|
const comment = useUserStore((state) => state.comment)
|
|
|
|
|
const userId = useUserStore((state) => state.userId) ?? ""
|
2023-03-19 11:26:09 +00:00
|
|
|
|
|
2024-02-19 20:21:17 +00:00
|
|
|
|
const [onChangeTypeLP, setOnChangeTypeLP] = useState<"email" | "password" | "all" | "">("")
|
|
|
|
|
|
|
|
|
|
const [readySend, setReadySend] = useState(false)
|
|
|
|
|
const [loginPasswordFocus, setLoginPasswordFocus] = useState(false)
|
|
|
|
|
|
|
|
|
|
const okLP = () => {
|
|
|
|
|
const ready = readySend
|
|
|
|
|
|
|
|
|
|
if (ready) {
|
|
|
|
|
handleSendDataClick()
|
|
|
|
|
}
|
|
|
|
|
setReadySend(false)
|
|
|
|
|
setOnChangeTypeLP("")
|
|
|
|
|
}
|
|
|
|
|
const cancelLP = () => {
|
|
|
|
|
const type = onChangeTypeLP
|
|
|
|
|
setOnChangeTypeLP("")
|
|
|
|
|
setReadySend(false)
|
|
|
|
|
console.log(type)
|
|
|
|
|
if (type === "email" && user?.email !== settingsFields.email.value) setSettingsField("email", user?.email || "")
|
|
|
|
|
if (type === "password") setSettingsField("password", "")
|
|
|
|
|
if (type === "all") {
|
|
|
|
|
setSettingsField("email", user?.email || "")
|
|
|
|
|
setSettingsField("password", "")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-16 15:27:39 +00:00
|
|
|
|
// useEffect(() => {
|
|
|
|
|
// verify(userId)
|
|
|
|
|
// }, [])
|
2023-06-02 08:22:14 +00:00
|
|
|
|
|
2023-11-05 23:33:40 +00:00
|
|
|
|
const textFieldProps = {
|
|
|
|
|
gap: upMd ? "16px" : "10px",
|
|
|
|
|
color: "#F2F3F7",
|
|
|
|
|
bold: true,
|
|
|
|
|
}
|
2023-05-30 18:34:41 +00:00
|
|
|
|
|
2024-02-19 20:21:17 +00:00
|
|
|
|
const trySendData = () => {
|
|
|
|
|
console.log("клик по сохранить")
|
|
|
|
|
if (user?.email !== settingsFields.email.value && settingsFields.password.value.length > 0) {
|
|
|
|
|
setReadySend(true)
|
|
|
|
|
setOnChangeTypeLP("all")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if (user?.email !== settingsFields.email.value) {
|
|
|
|
|
setReadySend(true)
|
|
|
|
|
setOnChangeTypeLP("email")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if (settingsFields.password.value.length > 0) {
|
|
|
|
|
setReadySend(true)
|
|
|
|
|
setOnChangeTypeLP("password")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
handleSendDataClick()
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-05 23:33:40 +00:00
|
|
|
|
function handleSendDataClick() {
|
|
|
|
|
sendUserData()
|
|
|
|
|
.then(() => {
|
|
|
|
|
enqueueSnackbar("Информация обновлена")
|
|
|
|
|
})
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
const message = getMessageFromFetchError(error)
|
|
|
|
|
if (message) enqueueSnackbar(message)
|
|
|
|
|
})
|
|
|
|
|
}
|
2023-06-24 18:17:43 +00:00
|
|
|
|
|
2023-11-05 23:33:40 +00:00
|
|
|
|
return (
|
|
|
|
|
<SectionWrapper
|
|
|
|
|
maxWidth="lg"
|
|
|
|
|
sx={{
|
|
|
|
|
mt: "25px",
|
|
|
|
|
mb: "70px",
|
|
|
|
|
px: isTablet ? (isMobile ? "18px" : "40px") : "20px",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<DocumentsDialog />
|
|
|
|
|
<Typography variant="h4" mt="20px">
|
2024-02-19 20:21:17 +00:00
|
|
|
|
Настройки аккаунта
|
2023-11-05 23:33:40 +00:00
|
|
|
|
</Typography>
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
mt: "40px",
|
|
|
|
|
mb: "40px",
|
|
|
|
|
backgroundColor: "white",
|
|
|
|
|
display: "flex",
|
|
|
|
|
flexDirection: "column",
|
|
|
|
|
borderRadius: "12px",
|
|
|
|
|
p: "20px",
|
|
|
|
|
gap: "40px",
|
|
|
|
|
boxShadow: cardShadow,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
display: "flex",
|
|
|
|
|
gap: "31px",
|
|
|
|
|
justifyContent: "space-between",
|
|
|
|
|
flexDirection: upMd ? "row" : "column",
|
|
|
|
|
}}
|
|
|
|
|
>
|
2024-02-19 20:21:17 +00:00
|
|
|
|
<UserFields
|
|
|
|
|
loginPasswordFocus={loginPasswordFocus}
|
|
|
|
|
setLoginPasswordFocus={setLoginPasswordFocus}
|
|
|
|
|
/>
|
2023-11-05 23:33:40 +00:00
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
maxWidth: "246px",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Typography variant="p1">Статус</Typography>
|
|
|
|
|
<VerificationIndicator verificationStatus={verificationStatus} sx={{ mt: "16px", p: "14px 7.5px" }} />
|
|
|
|
|
{verificationStatus === VerificationStatus.NOT_VERIFICATED && (
|
|
|
|
|
<>
|
|
|
|
|
<UnderlinedButtonWithIcon
|
|
|
|
|
icon={<UploadIcon />}
|
|
|
|
|
sx={{ mt: "55px" }}
|
|
|
|
|
ButtonProps={{
|
|
|
|
|
onClick: () => openDocumentsDialog("juridical"),
|
|
|
|
|
}}
|
|
|
|
|
>
|
2024-02-19 20:21:17 +00:00
|
|
|
|
Загрузить документы для юр лиц
|
2023-11-05 23:33:40 +00:00
|
|
|
|
</UnderlinedButtonWithIcon>
|
|
|
|
|
<UnderlinedButtonWithIcon
|
|
|
|
|
icon={<UploadIcon />}
|
|
|
|
|
sx={{ mt: "15px" }}
|
|
|
|
|
ButtonProps={{
|
|
|
|
|
onClick: () => openDocumentsDialog("nko"),
|
|
|
|
|
}}
|
|
|
|
|
>
|
2024-02-19 20:21:17 +00:00
|
|
|
|
Загрузить документы для НКО
|
2023-11-05 23:33:40 +00:00
|
|
|
|
</UnderlinedButtonWithIcon>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
{verificationStatus === VerificationStatus.VERIFICATED && (
|
|
|
|
|
<UnderlinedButtonWithIcon
|
|
|
|
|
icon={<EyeIcon />}
|
|
|
|
|
sx={{ mt: "55px" }}
|
|
|
|
|
ButtonProps={{
|
|
|
|
|
onClick: () => openDocumentsDialog(verificationType),
|
|
|
|
|
}}
|
|
|
|
|
>
|
2024-02-19 20:21:17 +00:00
|
|
|
|
Посмотреть свою верификацию
|
2023-11-05 23:33:40 +00:00
|
|
|
|
</UnderlinedButtonWithIcon>
|
|
|
|
|
)}
|
|
|
|
|
{comment && <p>{comment}</p>}
|
|
|
|
|
</Box>
|
|
|
|
|
</Box>
|
|
|
|
|
<Button
|
|
|
|
|
variant="pena-contained-dark"
|
2024-02-19 20:21:17 +00:00
|
|
|
|
onClick={trySendData}
|
|
|
|
|
disabled={settingsFields.hasError || loginPasswordFocus}
|
2023-11-05 23:33:40 +00:00
|
|
|
|
sx={{ alignSelf: "end" }}
|
|
|
|
|
>
|
2024-02-19 20:21:17 +00:00
|
|
|
|
Сохранить
|
2023-11-05 23:33:40 +00:00
|
|
|
|
</Button>
|
|
|
|
|
</Box>
|
2024-02-19 20:21:17 +00:00
|
|
|
|
<OnChangeLoginPassword
|
|
|
|
|
type={onChangeTypeLP}
|
|
|
|
|
ok={okLP}
|
|
|
|
|
cancel={cancelLP}
|
|
|
|
|
/>
|
2023-11-05 23:33:40 +00:00
|
|
|
|
</SectionWrapper>
|
|
|
|
|
)
|
2023-10-27 17:38:06 +00:00
|
|
|
|
}
|
2023-05-30 18:34:41 +00:00
|
|
|
|
|
2023-10-27 17:38:06 +00:00
|
|
|
|
export default withErrorBoundary(AccountSettings, {
|
2023-11-05 23:33:40 +00:00
|
|
|
|
fallback: <Typography mt="8px" textAlign="center">Ошибка при отображении настроек аккаунта</Typography>,
|
|
|
|
|
onError: handleComponentError,
|
2023-10-27 17:38:06 +00:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const verificationStatusData: Record<VerificationStatus, { text: string; color: string; }> = {
|
2023-11-05 23:33:40 +00:00
|
|
|
|
verificated: { text: "Верификация пройдена", color: "#0D9F00" },
|
|
|
|
|
waiting: { text: "В ожидании верификации", color: "#F18956" },
|
|
|
|
|
notVerificated: { text: "Не верифицирован", color: "#E02C2C" },
|
|
|
|
|
}
|
2023-07-06 21:52:07 +00:00
|
|
|
|
|
2023-10-27 17:38:06 +00:00
|
|
|
|
function VerificationIndicator({
|
2023-11-05 23:33:40 +00:00
|
|
|
|
verificationStatus,
|
|
|
|
|
sx,
|
2023-10-27 17:38:06 +00:00
|
|
|
|
}: {
|
2024-02-19 20:21:17 +00:00
|
|
|
|
verificationStatus: VerificationStatus;
|
|
|
|
|
sx?: SxProps<Theme>;
|
2023-10-27 17:38:06 +00:00
|
|
|
|
}) {
|
2023-11-05 23:33:40 +00:00
|
|
|
|
return (
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
py: "14px",
|
|
|
|
|
px: "8.5px",
|
|
|
|
|
borderWidth: "1px",
|
|
|
|
|
borderStyle: "solid",
|
|
|
|
|
color: verificationStatusData[verificationStatus].color,
|
|
|
|
|
borderColor: verificationStatusData[verificationStatus].color,
|
|
|
|
|
borderRadius: "8px",
|
|
|
|
|
textAlign: "center",
|
|
|
|
|
...sx,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Typography lineHeight="100%">{verificationStatusData[verificationStatus].text}</Typography>
|
|
|
|
|
</Box>
|
|
|
|
|
)
|
2023-10-27 23:43:29 +00:00
|
|
|
|
}
|