25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

613 lines
35 KiB

  1. // material-ui
  2. import {
  3. FormControl,
  4. Button,
  5. Grid,
  6. Typography, FormLabel,
  7. OutlinedInput,
  8. Stack,
  9. Dialog, DialogTitle, DialogContent, DialogActions, InputAdornment,
  10. } from '@mui/material';
  11. import {isGranted, delBugMode } from "auth/utils";
  12. const MainCard = Loadable(lazy(() => import('components/MainCard')));
  13. import { useForm } from "react-hook-form";
  14. import {
  15. useEffect,
  16. useState
  17. } from "react";
  18. import Loadable from 'components/Loadable';
  19. import { lazy } from 'react';
  20. const LoadingComponent = Loadable(lazy(() => import('../../extra-pages/LoadingComponent')));
  21. import * as HttpUtils from "utils/HttpUtils"
  22. import * as DateUtils from "utils/DateUtils"
  23. import * as UrlUtils from "utils/ApiPathConst"
  24. import * as StatusUtils from "utils/statusUtils/PublicNoteStatusUtils";
  25. import DoneIcon from '@mui/icons-material/Done';
  26. import CloseIcon from '@mui/icons-material/Close';
  27. import EditNoteIcon from '@mui/icons-material/EditNote';
  28. import DownloadIcon from '@mui/icons-material/Download';
  29. import ReplayIcon from '@mui/icons-material/Replay';
  30. import { notifyDownloadSuccess } from 'utils/CommonFunction';
  31. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  32. const ApplicationDetailCard = (
  33. { applicationDetailData,
  34. setStatus,
  35. setUploadStatus
  36. }
  37. ) => {
  38. const [currentApplicationDetailData, setCurrentApplicationDetailData] = useState({});
  39. const [companyName, setCompanyName] = useState({});
  40. const [verified, setVerified] = useState(null);
  41. const [fileDetail, setfileDetail] = useState({});
  42. const [onReady, setOnReady] = useState(false);
  43. const { register } = useForm()
  44. const [isWarningPopUp, setIsWarningPopUp] = useState(false);
  45. const [warningText, setWarningText] = useState("");
  46. useEffect(() => {
  47. //if user data from parent are not null
  48. // console.log(applicationDetailData)
  49. if (Object.keys(applicationDetailData).length > 0) {
  50. loadApplicationDetail()
  51. }
  52. }, [applicationDetailData]);
  53. useEffect(() => {
  54. //if state data are ready and assign to different field
  55. // console.log(currentApplicationDetailData)
  56. if (Object.keys(currentApplicationDetailData).length > 0) {
  57. setOnReady(true);
  58. }
  59. }, [currentApplicationDetailData]);
  60. const loadApplicationDetail = () => {
  61. setCurrentApplicationDetailData(applicationDetailData.data);
  62. setCompanyName(applicationDetailData.companyName);
  63. setVerified(applicationDetailData.userData.verifiedBy ? true : false)
  64. setfileDetail(applicationDetailData.fileDetail);
  65. // setReload(false)
  66. }
  67. const onDownloadClick = () => () => {
  68. HttpUtils.fileDownload({
  69. fileId: fileDetail?.id,
  70. skey: fileDetail?.skey,
  71. filename: fileDetail?.filename,
  72. });
  73. notifyDownloadSuccess()
  74. setUploadStatus(true)
  75. };
  76. const reSubmitClick = () => () => {
  77. setStatus("resubmit")
  78. };
  79. const notAcceptedClick = () => () => {
  80. setStatus("notAccepted")
  81. };
  82. const setCompleteDisable = () => {
  83. if (delBugMode) return false;
  84. return (new Date()).getTime() < DateUtils.convertToDate(applicationDetailData.gazetteIssueDetail.issueDate).getTime();
  85. }
  86. const complatedClick = () => () => {
  87. let issueDate = DateUtils.convertToDate(applicationDetailData.gazetteIssueDetail.issueDate);
  88. let current = new Date();
  89. if (delBugMode) {
  90. setStatus("complete")
  91. } else if (current.getTime() >= issueDate.getTime()) {
  92. setStatus("complete")
  93. }
  94. };
  95. const withdrawnClick = () => () => {
  96. setStatus("withdraw")
  97. };
  98. const doPublish = () => () => {
  99. setStatus("publish")
  100. }
  101. const onProofClick = () => {
  102. if (applicationDetailData.data.groupNo) {
  103. HttpUtils.get({
  104. url: UrlUtils.CHECK_CREATE_PROOF + "/" + currentApplicationDetailData.id,
  105. onSuccess: function (responeData) {
  106. if (responeData.success == true) {
  107. window.open("/proof/create/" + currentApplicationDetailData.id, "_blank", "noreferrer");
  108. window.addEventListener("focus", onFocus)
  109. } else {
  110. let msg = responeData.msg;
  111. if (msg === "haveActiveProof") {
  112. msg = "Action Failed: There is already a pending payment and proofreading record for client review."
  113. } else if (msg === "haveProofed") {
  114. msg = "Action Failed: Already proofed."
  115. }
  116. setWarningText(msg);
  117. setIsWarningPopUp(true);
  118. }
  119. }
  120. });
  121. } else {
  122. setWarningText("Please generate Gazette Code before Create Proof.");
  123. setIsWarningPopUp(true);
  124. }
  125. }
  126. const onFocus = () => {
  127. location.reload();
  128. window.removeEventListener("focus", onFocus)
  129. }
  130. return (
  131. !onReady ?
  132. <LoadingComponent />
  133. :
  134. <MainCard elevation={0}
  135. border={false}
  136. content={false}
  137. >
  138. {verified && currentApplicationDetailData.status !== "notAccepted" ?
  139. <Grid container spacing={4} direction="row">
  140. <Grid item xs={12} md={4} >
  141. <Stack
  142. direction="row"
  143. justifyContent="flex-start"
  144. alignItems="center"
  145. spacing={2}
  146. mb={2}
  147. >
  148. {currentApplicationDetailData.status === "reviewed" && isGranted("MAINTAIN_PROOF") ?
  149. <Button
  150. // size="large"
  151. variant="contained"
  152. onClick={() => { onProofClick() }}
  153. sx={{
  154. textTransform: 'capitalize',
  155. alignItems: 'end'
  156. }}>
  157. <EditNoteIcon />
  158. <Typography ml={1} variant="h5"> Create Proof</Typography>
  159. </Button> :
  160. null
  161. }
  162. </Stack>
  163. </Grid>
  164. <Grid item xs={12} md={8} >
  165. <Stack
  166. direction="row"
  167. justifyContent="flex-start"
  168. alignItems="center"
  169. spacing={2}
  170. mb={2}
  171. >
  172. {currentApplicationDetailData.status === "submitted" || currentApplicationDetailData.status == "reviewed" ?
  173. <>
  174. <Button
  175. // size="large"
  176. variant="contained"
  177. onClick={reSubmitClick()}
  178. color="orange"
  179. >
  180. <ReplayIcon />
  181. <Typography ml={1} variant="h5"> Re-Submit</Typography>
  182. </Button>
  183. <Button
  184. // size="large"
  185. variant="contained"
  186. onClick={notAcceptedClick()}
  187. color="error"
  188. sx={{
  189. textTransform: 'capitalize',
  190. alignItems: 'end',
  191. }}>
  192. <CloseIcon />
  193. <Typography ml={1} variant="h5">Not Accept</Typography>
  194. </Button>
  195. </> :
  196. (currentApplicationDetailData.status == "confirmed" && currentApplicationDetailData.creditor == 1) ?
  197. <>
  198. <Button
  199. // size="large"
  200. variant="contained"
  201. onClick={doPublish()}
  202. disabled={setCompleteDisable()}
  203. sx={{
  204. textTransform: 'capitalize',
  205. alignItems: 'end',
  206. backgroundColor: '#52b202'
  207. }}>
  208. <DoneIcon />
  209. <Typography ml={1} variant="h5">Publish</Typography>
  210. </Button>
  211. <Button
  212. // size="large"
  213. variant="contained"
  214. onClick={withdrawnClick()}
  215. sx={{
  216. textTransform: 'capitalize',
  217. alignItems: 'end',
  218. backgroundColor: '#ffa733'
  219. }}>
  220. <CloseIcon />
  221. <Typography ml={1} variant="h5">Withdraw</Typography>
  222. </Button>
  223. </>
  224. :
  225. (currentApplicationDetailData.status == "confirmed" && currentApplicationDetailData.creditor == 0) ?
  226. <>
  227. <Button
  228. // size="large"
  229. variant="contained"
  230. onClick={withdrawnClick()}
  231. sx={{
  232. textTransform: 'capitalize',
  233. alignItems: 'end',
  234. backgroundColor: '#ffa733'
  235. }}>
  236. <CloseIcon />
  237. <Typography ml={1} variant="h5">Withdraw</Typography>
  238. </Button>
  239. </>
  240. :
  241. (
  242. (currentApplicationDetailData.status == "paid" && currentApplicationDetailData.creditor == 0) ?
  243. <>
  244. <Button
  245. // size="large"
  246. variant="contained"
  247. onClick={complatedClick()}
  248. disabled={setCompleteDisable()}
  249. sx={{
  250. textTransform: 'capitalize',
  251. alignItems: 'end',
  252. backgroundColor: '#52b202'
  253. }}>
  254. <DoneIcon />
  255. <Typography ml={1} variant="h5">Publish</Typography>
  256. </Button>
  257. <Button
  258. // size="large"
  259. variant="contained"
  260. onClick={withdrawnClick()}
  261. sx={{
  262. textTransform: 'capitalize',
  263. alignItems: 'end',
  264. backgroundColor: '#ffa733'
  265. }}>
  266. <CloseIcon />
  267. <Typography ml={1} variant="h5">Withdraw</Typography>
  268. </Button>
  269. </> : null
  270. )
  271. }
  272. </Stack>
  273. </Grid>
  274. </Grid> : null
  275. }
  276. <Typography variant="h4" xs={12} md={12} sx={{ mb: 2, borderBottom: "1px solid black" }}>
  277. Application Details
  278. </Typography>
  279. <form>
  280. <Grid container direction="column">
  281. <Grid item xs={12} md={12}>
  282. <Grid container direction="row" justifyContent="flex-start"
  283. alignItems="center">
  284. <Grid item xs={12} md={6} lg={6} sx={{ mb: 1 }}>
  285. <Grid container alignItems={"center"}>
  286. <Grid item xs={12} md={4} lg={4}
  287. sx={{ display: 'flex', alignItems: 'center' }}>
  288. <FormLabel><Typography variant="h5">Application No:</Typography></FormLabel>
  289. </Grid>
  290. <Grid item xs={12} md={8} lg={8}>
  291. <FormControl variant="outlined" fullWidth disabled >
  292. <OutlinedInput
  293. fullWidth
  294. size="small"
  295. {...register("appNo",
  296. {
  297. value: currentApplicationDetailData.appNo,
  298. })}
  299. id='appNo'
  300. sx={{
  301. "& .MuiInputBase-input.Mui-disabled": {
  302. WebkitTextFillColor: "#000000",
  303. background: "#f8f8f8",
  304. },
  305. }}
  306. />
  307. </FormControl>
  308. </Grid>
  309. </Grid>
  310. </Grid>
  311. <Grid item xs={12} sm={12} md={5.5} lg={5.5} sx={{ mb: 1, ml: { md: 1, lg: 3 } }}>
  312. <Grid container alignItems={"center"}>
  313. <Grid item xs={12} md={4} lg={4}
  314. sx={{ display: 'flex', alignItems: 'center' }}>
  315. <FormLabel><Typography variant="h5">Status:</Typography></FormLabel>
  316. </Grid>
  317. <Grid item xs={12} md={8} lg={8}>
  318. <FormControl variant="outlined">
  319. {StatusUtils.getStatusByTextEng(currentApplicationDetailData.status, currentApplicationDetailData.creditor)}
  320. </FormControl>
  321. </Grid>
  322. </Grid>
  323. </Grid>
  324. </Grid>
  325. <Grid container direction="row" justifyContent="flex-start"
  326. alignItems="center">
  327. <Grid item xs={12} md={6} lg={6} sx={{ mb: 1 }}>
  328. <Grid container alignItems={"center"}>
  329. <Grid item xs={12} md={4} lg={4}
  330. sx={{ display: 'flex', alignItems: 'center' }}>
  331. <FormLabel><Typography variant="h5">Applicant:</Typography></FormLabel>
  332. </Grid>
  333. <Grid item xs={12} md={8} lg={8}>
  334. <FormControl variant="outlined" fullWidth disabled >
  335. {currentApplicationDetailData.orgId === null ?
  336. <OutlinedInput
  337. fullWidth
  338. size="small"
  339. {...register("contactPerson",
  340. {
  341. value: currentApplicationDetailData.contactPerson,
  342. })}
  343. id='contactPerson'
  344. sx={{
  345. "& .MuiInputBase-input.Mui-disabled": {
  346. WebkitTextFillColor: "#000000",
  347. background: "#f8f8f8",
  348. },
  349. }}
  350. /> :
  351. <OutlinedInput
  352. fullWidth
  353. size="small"
  354. {...register("companyName",
  355. {
  356. value: companyName.enCompanyName,
  357. })}
  358. id='companyName'
  359. sx={{
  360. "& .MuiInputBase-input.Mui-disabled": {
  361. WebkitTextFillColor: "#000000",
  362. background: "#f8f8f8",
  363. },
  364. }}
  365. />
  366. }
  367. </FormControl>
  368. </Grid>
  369. </Grid>
  370. </Grid>
  371. <Grid item xs={12} md={5.5} lg={5.5} sx={{ mb: 1, ml: { md: 1, lg: 3 } }}>
  372. <Grid container alignItems={"center"}>
  373. <Grid item xs={12} md={4} lg={4}
  374. sx={{ display: 'flex', alignItems: 'center' }}>
  375. <FormLabel><Typography variant="h5">Contact Phone:</Typography></FormLabel>
  376. </Grid>
  377. <Grid item xs={12} md={8} lg={8}>
  378. <Stack direction="row">
  379. <FormControl variant="outlined" sx={{ width: '25%', minWidth: 100, }} disabled >
  380. <OutlinedInput
  381. size="small"
  382. {...register("contactTelNo.countryCode",
  383. {
  384. value: currentApplicationDetailData.contactTelNo.countryCode,
  385. })}
  386. id='countryCode'
  387. sx={{
  388. "& .MuiInputBase-input.Mui-disabled": {
  389. WebkitTextFillColor: "#000000",
  390. background: "#f8f8f8",
  391. },
  392. mr: 1
  393. }}
  394. inputProps={{
  395. maxLength: 3,
  396. }}
  397. endAdornment={<InputAdornment position="end">-</InputAdornment>}
  398. />
  399. </FormControl>
  400. <FormControl variant="outlined" sx={{ width: '75%' }} disabled >
  401. <OutlinedInput
  402. size="small"
  403. type="tel"
  404. {...register("contactTelNo.phoneNumber",
  405. {
  406. value: currentApplicationDetailData.contactTelNo.phoneNumber,
  407. })}
  408. id='phoneNumber'
  409. sx={{
  410. "& .MuiInputBase-input.Mui-disabled": {
  411. WebkitTextFillColor: "#000000",
  412. background: "#f8f8f8",
  413. },
  414. }}
  415. inputProps={{
  416. maxLength: 11,
  417. }}
  418. />
  419. </FormControl>
  420. </Stack>
  421. </Grid>
  422. </Grid>
  423. </Grid>
  424. </Grid>
  425. <Grid container direction="row" justifyContent="flex-start"
  426. alignItems="center">
  427. <Grid item xs={12} md={6} lg={6} sx={{ mb: 1 }}>
  428. <Grid container alignItems={"center"}>
  429. <Grid item xs={12} md={4} lg={4}
  430. sx={{ display: 'flex', alignItems: 'center' }}>
  431. <FormLabel><Typography variant="h5">Contact Person:</Typography></FormLabel>
  432. </Grid>
  433. <Grid item xs={12} md={8} lg={8}>
  434. <FormControl variant="outlined" fullWidth disabled>
  435. <OutlinedInput
  436. fullWidth
  437. size="small"
  438. {...register("contactPerson",
  439. {
  440. value: currentApplicationDetailData.contactPerson,
  441. })}
  442. id='contactPerson'
  443. sx={{
  444. "& .MuiInputBase-input.Mui-disabled": {
  445. WebkitTextFillColor: "#000000",
  446. background: "#f8f8f8",
  447. },
  448. }}
  449. />
  450. </FormControl>
  451. </Grid>
  452. </Grid>
  453. </Grid>
  454. <Grid item xs={12} md={5.5} lg={5.5} sx={{ mb: 1, ml: { md: 1, lg: 3 } }}>
  455. <Grid container alignItems={"center"}>
  456. <Grid item xs={12} md={4} lg={4}
  457. sx={{ display: 'flex', alignItems: 'center' }}>
  458. <FormLabel><Typography variant="h5">Contact Fax:</Typography></FormLabel>
  459. </Grid>
  460. <Grid item xs={12} md={8} lg={8}>
  461. <Stack direction="row">
  462. <FormControl variant="outlined" sx={{ width: '25%', minWidth: 100, }} disabled>
  463. <OutlinedInput
  464. size="small"
  465. {...register("contactFaxNo.countryCode",
  466. {
  467. value: currentApplicationDetailData.contactFaxNo.countryCode,
  468. })}
  469. id='countryCode'
  470. sx={{
  471. "& .MuiInputBase-input.Mui-disabled": {
  472. WebkitTextFillColor: "#000000",
  473. background: "#f8f8f8",
  474. },
  475. mr: 1,
  476. }}
  477. inputProps={{
  478. maxLength: 3,
  479. type: "tel"
  480. }}
  481. endAdornment={<InputAdornment position="end">-</InputAdornment>}
  482. />
  483. </FormControl>
  484. <FormControl variant="outlined" sx={{ width: '75%' }} disabled>
  485. <OutlinedInput
  486. size="small"
  487. type="tel"
  488. {...register("contactFaxNo.faxNumber",
  489. {
  490. value: currentApplicationDetailData.contactFaxNo.faxNumber,
  491. })}
  492. id='faxNumber'
  493. sx={{
  494. "& .MuiInputBase-input.Mui-disabled": {
  495. WebkitTextFillColor: "#000000",
  496. background: "#f8f8f8",
  497. },
  498. }}
  499. inputProps={{
  500. maxLength: 8,
  501. }}
  502. />
  503. </FormControl>
  504. </Stack>
  505. </Grid>
  506. </Grid>
  507. </Grid>
  508. </Grid>
  509. <Grid container direction="row" justifyContent="flex-start"
  510. alignItems="center">
  511. <Grid item xs={12} md={12} lg={12} mt={1} >
  512. <Grid container alignItems={"center"}>
  513. <Grid item xs={12} md={12} lg={12}>
  514. <Grid container direction="row">
  515. <Grid item xs={12} md={2} lg={2}
  516. sx={{ display: 'flex', alignItems: 'center' }}>
  517. <FormLabel><Typography variant="h5" >Manuscript File:</Typography></FormLabel>
  518. </Grid>
  519. <Grid item xs={12} md={8} lg={8} sx={{ display: 'flex', alignItems: 'center' }}>
  520. <Grid container direction="row" justifyContent="flex-start">
  521. <Grid item xs={10} md={8} lg={8} sx={{ display: 'flex', alignItems: 'center' }}>
  522. <FormControl variant="outlined" fullWidth >
  523. <Typography
  524. // fullWidth
  525. id='fileName'
  526. variant="h5"
  527. sx={{ wordBreak: 'break-word' }}
  528. >
  529. {fileDetail?.filename}
  530. </Typography>
  531. </FormControl>
  532. </Grid>
  533. <Grid item md={2} lg={2}>
  534. <Button
  535. size="small"
  536. variant="contained"
  537. onClick={onDownloadClick()}
  538. disabled={!fileDetail?.filename}
  539. sx={{
  540. textTransform: 'capitalize',
  541. alignItems: 'end',
  542. }}>
  543. <DownloadIcon />
  544. </Button>
  545. </Grid>
  546. </Grid>
  547. </Grid>
  548. </Grid>
  549. </Grid>
  550. </Grid>
  551. </Grid>
  552. </Grid>
  553. </Grid>
  554. </Grid>
  555. </form>
  556. <div>
  557. <Dialog
  558. open={isWarningPopUp}
  559. onClose={() => setIsWarningPopUp(false)}
  560. PaperProps={{
  561. sx: {
  562. minWidth: '40vw',
  563. maxWidth: { xs: '90vw', s: '90vw', m: '70vw', lg: '70vw' },
  564. maxHeight: { xs: '90vh', s: '70vh', m: '70vh', lg: '60vh' }
  565. }
  566. }}
  567. >
  568. <DialogTitle><Typography variant="h3">Warning</Typography></DialogTitle>
  569. <DialogContent style={{ display: 'flex', }}>
  570. <Typography variant="h4" style={{ padding: '16px' }}>{warningText}</Typography>
  571. </DialogContent>
  572. <DialogActions>
  573. <Button onClick={() => setIsWarningPopUp(false)}><Typography variant="h5">OK</Typography></Button>
  574. </DialogActions>
  575. </Dialog>
  576. </div>
  577. </MainCard>
  578. );
  579. };
  580. export default ApplicationDetailCard;