2023-11-05 23:33:40 +00:00
import { Box , Button , Dialog , IconButton , Typography } from "@mui/material"
import { enqueueSnackbar } from "notistack"
import CloseSmallIcon from "@root/components/icons/CloseSmallIcon"
2023-09-08 07:51:24 +00:00
import {
2023-11-05 23:33:40 +00:00
closeDocumentsDialog ,
setDocument ,
useUserStore ,
} from "@root/stores/user"
import DocumentUploadItem from "./DocumentUploadItem"
import DocumentItem from "./DocumentItem"
import { verify } from "../helper"
import { VerificationStatus } from "@root/model/account"
import { sendDocuments , updateDocuments } from "@root/api/verification"
import { readFile } from "@root/utils/readFile"
import { deleteEmptyKeys } from "@root/utils/deleteEmptyKeys"
import { useState } from "react"
import { theme } from "@root/utils/theme"
2023-06-02 08:22:14 +00:00
2023-09-11 13:45:14 +00:00
const dialogContainerStyle = {
2023-11-05 23:33:40 +00:00
height : "100%" ,
overflowY : "scroll" ,
}
2023-09-11 13:45:14 +00:00
2023-06-02 08:22:14 +00:00
export default function NkoDocumentsDialog() {
2023-11-05 23:33:40 +00:00
const isOpen = useUserStore ( ( state ) = > state . isDocumentsDialogOpen )
const verificationStatus = useUserStore ( ( state ) = > state . verificationStatus )
const documents = useUserStore ( ( state ) = > state . documents )
const documentsUrl = useUserStore ( ( state ) = > state . documentsUrl )
const userId = useUserStore ( ( state ) = > state . userId ) ? ? ""
2023-06-02 08:22:14 +00:00
2023-11-05 23:33:40 +00:00
const sendUploadedDocuments = async ( ) = > {
if (
documents [ "ИНН" ] . file &&
2023-09-15 12:28:46 +00:00
documents [ "Устав" ] . file &&
documents [ "Свидетельство о регистрации Н К О " ] . file
2023-10-27 23:13:54 +00:00
&& ! documentsUrl [ "ИНН" ] && ! documentsUrl [ "Устав" ] && ! documentsUrl [ "Свидетельство о регистрации Н К О " ]
2023-11-05 23:33:40 +00:00
) {
closeDocumentsDialog ( )
//Пользователь заполнил все поля и на беке пусто
const inn = await readFile ( documents [ "ИНН" ] . file , "binary" )
const rule = await readFile ( documents [ "Устав" ] . file , "binary" )
const certificate = await readFile (
documents [ "Свидетельство о регистрации Н К О " ] . file ,
"binary"
)
2023-09-15 12:28:46 +00:00
2023-11-05 23:33:40 +00:00
const [ _ , sendDocumentsError ] = await sendDocuments ( {
status : "nko" ,
inn ,
rule ,
certificate ,
} )
2023-09-15 12:28:46 +00:00
2023-11-05 23:33:40 +00:00
if ( sendDocumentsError ) {
enqueueSnackbar ( sendDocumentsError )
2023-09-15 12:28:46 +00:00
2023-11-05 23:33:40 +00:00
return
}
if ( _ === "OK" ) {
enqueueSnackbar ( "Информация доставлена" )
}
2023-09-15 12:28:46 +00:00
2023-11-05 23:33:40 +00:00
setDocument ( "ИНН" , null )
setDocument ( "Устав" , null )
setDocument ( "Свидетельство о регистрации Н К О " , null )
2023-10-27 23:13:54 +00:00
2023-11-05 23:33:40 +00:00
await verify ( userId )
} else { //Пользователь заполнил не все, или на беке что-то есть
if ( ( documents [ "ИНН" ] . file || documents [ "Устав" ] . file || documents [ "Свидетельство о регистрации Н К О " ] . file ) && ( documentsUrl [ "ИНН" ] || documentsUrl [ "Устав" ] || documentsUrl [ "Свидетельство о регистрации Н К О " ] ) ) { //минимум 1 поле заполнено на фронте и минимум 1 поле на беке записано
closeDocumentsDialog ( )
const inn = documents [ "ИНН" ] . file
? await readFile ( documents [ "ИНН" ] . file , "binary" )
: undefined
const rule = documents [ "Устав" ] . file
? await readFile ( documents [ "Устав" ] . file , "binary" )
: undefined
const certificate = documents [ "Свидетельство о регистрации Н К О " ] . file
? await readFile (
documents [ "Свидетельство о регистрации Н К О " ] . file ,
"binary"
)
: undefined
2023-09-15 12:28:46 +00:00
2023-11-05 23:33:40 +00:00
const [ _ , updateDocumentsError ] = await updateDocuments (
deleteEmptyKeys ( {
2024-05-22 20:41:34 +00:00
status : "nko" ,
2023-11-05 23:33:40 +00:00
inn ,
rule ,
certificate ,
} )
)
2023-09-15 12:28:46 +00:00
2023-11-05 23:33:40 +00:00
if ( updateDocumentsError ) {
enqueueSnackbar ( updateDocumentsError )
2023-09-08 07:51:24 +00:00
2023-11-05 23:33:40 +00:00
return
}
if ( _ === "OK" ) {
enqueueSnackbar ( "Информация доставлена" )
}
2023-07-06 21:52:07 +00:00
2023-11-05 23:33:40 +00:00
setDocument ( "ИНН" , null )
setDocument ( "Устав" , null )
setDocument ( "Свидетельство о регистрации Н К О " , null )
2023-10-27 23:13:54 +00:00
2023-11-05 23:33:40 +00:00
await verify ( userId )
}
}
2023-07-06 21:52:07 +00:00
2023-11-05 23:33:40 +00:00
}
2023-07-06 21:52:07 +00:00
2023-11-05 23:33:40 +00:00
const disbutt = ( ) = > {
if ( documents [ "ИНН" ] . file && documents [ "Устав" ] . file && documents [ "Свидетельство о регистрации Н К О " ] . file && ! documentsUrl [ "ИНН" ] && ! documentsUrl [ "Устав" ] && ! documentsUrl [ "Свидетельство о регистрации Н К О " ] ) { //post
//все поля заполнены и на беке пусто
return false
} else { //patch
if ( documents [ "ИНН" ] . file || documents [ "Устав" ] . file || documents [ "Свидетельство о регистрации Н К О " ] . file ) {
//минимум одно поле заполнено
return false
}
return true
}
}
2023-10-27 23:13:54 +00:00
2023-11-05 23:33:40 +00:00
const documentElements =
2023-09-04 20:01:24 +00:00
verificationStatus === VerificationStatus . VERIFICATED ? (
2023-11-05 23:33:40 +00:00
< >
< DocumentItem
text = "1. Свидетельство о регистрации Н К О "
2024-05-22 02:19:20 +00:00
keyName = "certificate"
2023-11-05 23:33:40 +00:00
documentUrl = { documentsUrl [ "Свидетельство о регистрации Н К О " ] }
/ >
< DocumentItem
text = "2. Скан ИНН организации Н К О (выписка из ЕГЮРЛ)"
2024-05-22 02:19:20 +00:00
keyName = "inn"
2023-11-05 23:33:40 +00:00
documentUrl = { documentsUrl [ "ИНН" ] }
/ >
< DocumentItem
text = "3. Устав организации"
documentUrl = { documentsUrl [ "Устав" ] }
2024-05-22 02:19:20 +00:00
keyName = "rule"
2023-11-05 23:33:40 +00:00
/ >
< / >
2023-09-04 20:01:24 +00:00
) : (
2023-11-05 23:33:40 +00:00
< >
< DocumentUploadItem
text = "1. Свидетельство о регистрации Н К О "
accept = "application/pdf"
document = { documents [ "Свидетельство о регистрации Н К О " ] }
documentUrl = { documentsUrl [ "Свидетельство о регистрации Н К О " ] }
onFileChange = { ( e ) = >
setDocument (
"Свидетельство о регистрации Н К О " ,
e . target ? . files ? . [ 0 ] || null
)
}
/ >
< DocumentUploadItem
text = "2. Скан ИНН организации Н К О (выписка из ЕГЮРЛ)"
accept = "application/pdf"
document = { documents [ "ИНН" ] }
documentUrl = { documentsUrl [ "ИНН" ] }
onFileChange = { ( e ) = > setDocument ( "ИНН" , e . target ? . files ? . [ 0 ] || null ) }
/ >
< DocumentUploadItem
text = "3. Устав организации"
accept = "application/pdf"
document = { documents [ "Устав" ] }
documentUrl = { documentsUrl [ "Устав" ] }
onFileChange = { ( e ) = >
setDocument ( "Устав" , e . target ? . files ? . [ 0 ] || null )
}
/ >
< / >
)
2023-06-02 08:22:14 +00:00
2023-11-05 23:33:40 +00:00
return (
< Dialog
open = { isOpen }
onClose = { closeDocumentsDialog }
PaperProps = { {
sx : {
width : "600px" ,
maxWidth : "600px" ,
backgroundColor : "white" ,
position : "relative" ,
display : "flex" ,
flexDirection : "column" ,
gap : "20px" ,
borderRadius : "12px" ,
boxShadow : "none" ,
overflowY : "hidden" ,
} ,
} }
slotProps = { {
backdrop : { style : { backgroundColor : "rgb(0 0 0 / 0.7)" } } ,
} }
>
< IconButton
onClick = { closeDocumentsDialog }
sx = { {
position : "absolute" ,
right : "7px" ,
top : "7px" ,
} }
>
< CloseSmallIcon / >
< / IconButton >
< Box sx = { { p : "40px" , overflowY : "scroll" } } >
< Typography variant = "h5" lineHeight = "100%" >
{ verificationStatus === VerificationStatus . VERIFICATED
? "Ваши документы"
: "Загрузите документы" }
< / Typography >
< Typography
sx = { {
fontWeight : 400 ,
fontSize : "16px" ,
lineHeight : "100%" ,
mt : "12px" ,
} }
>
2023-09-04 20:01:24 +00:00
д л я в е р и ф и к а ц и и Н К О в ф о р м а т е PDF
2023-11-05 23:33:40 +00:00
< / Typography >
{ Boolean ( ! documentsUrl [ "ИНН" ] && ! documentsUrl [ "Устав" ] && ! documentsUrl [ "Свидетельство о регистрации Н К О " ] ) && < Typography
sx = { {
fontWeight : 400 ,
fontSize : "16px" ,
lineHeight : "100%" ,
mt : "12px" ,
color : theme.palette.purple.main
} }
>
2023-10-27 23:13:54 +00:00
П о ж а л у й с т а , з а п о л н и т е в с е п о л я !
2023-11-05 23:33:40 +00:00
< / Typography > }
< Box sx = { dialogContainerStyle } >
< Box
sx = { {
maxHeight : "280px" ,
mt : "30px" ,
display : "flex" ,
flexDirection : "column" ,
gap : "25px" ,
} }
>
{ documentElements }
< / Box >
< / Box >
< / Box >
{ verificationStatus === VerificationStatus . NOT_VERIFICATED && (
< Button
sx = { { position : "absolute" , bottom : "20px" , right : "20px" } }
onClick = { sendUploadedDocuments }
variant = "pena-contained-dark"
disabled = { disbutt ( ) }
>
2023-09-04 20:01:24 +00:00
О т п р а в и т ь
2023-11-05 23:33:40 +00:00
< / Button >
) }
< > < / >
< / Dialog >
)
2023-09-16 16:29:37 +00:00
}