選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

OrganizationCard.js 20 KiB

2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. // material-ui
  2. import {
  3. Grid, Button, Checkbox, FormControlLabel, Typography,
  4. Dialog, DialogTitle, DialogContent, DialogActions,
  5. } from '@mui/material';
  6. // import { FormControlLabel } from '@material-ui/core';
  7. import MainCard from "../../../components/MainCard";
  8. import * as React from "react";
  9. import { useFormik } from 'formik';
  10. import * as yup from 'yup';
  11. import { useEffect, useState } from "react";
  12. import * as HttpUtils from '../../../utils/HttpUtils';
  13. import * as UrlUtils from "../../../utils/ApiPathConst";
  14. import * as FieldUtils from "../../../utils/FieldUtils";
  15. import * as ComboData from "../../../utils/ComboData";
  16. const LoadingComponent = Loadable(lazy(() => import('../../extra-pages/LoadingComponent')));
  17. import Loadable from 'components/Loadable';
  18. import { lazy } from 'react';
  19. import { notifySaveSuccess } from 'utils/CommonFunction';
  20. import {useIntl} from "react-intl";
  21. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  22. const OrganizationCard = ({ userData, loadDataFun, id, setEditModeFun }) => {
  23. const intl = useIntl();
  24. const [creditorConfirmPopUp, setCreditorConfirmPopUp] = React.useState(false);
  25. const [nonCreditorConfirmPopUp, setNonCreditorConfirmPopUp] = React.useState(false);
  26. const [currentUserData, setCurrentUserData] = useState({});
  27. const [editMode, setEditMode] = useState(false);
  28. const [createMode, setCreateMode] = useState(false);
  29. const [onReady, setOnReady] = useState(false);
  30. useEffect(() => {
  31. //if state data are ready and assign to different field
  32. // console.log(currentApplicationDetailData)
  33. if (Object.keys(currentUserData).length > 0) {
  34. setOnReady(true);
  35. }
  36. }, [currentUserData]);
  37. function displayErrorMsg(errorMsg) {
  38. return <Typography variant="errorMessage1">{errorMsg}</Typography>
  39. }
  40. const formik = useFormik({
  41. enableReinitialize: true,
  42. initialValues: currentUserData,
  43. validationSchema: yup.object().shape({
  44. enCompanyName: yup.string().max(255).required(displayErrorMsg(intl.formatMessage({id: 'userRequireEnglishName'}))),
  45. chCompanyName: yup.string().max(255, displayErrorMsg(intl.formatMessage({id: 'userRequireChineseName'}))).nullable(),
  46. addressLine1: yup.string().max(255).required(displayErrorMsg(intl.formatMessage({id: 'validateAddressLine1'}))),
  47. addressLine2: yup.string().max(255, displayErrorMsg(intl.formatMessage({id: 'noMoreThen255Words'}))),
  48. addressLine3: yup.string().max(255, displayErrorMsg(intl.formatMessage({id: 'noMoreThen255Words'}))),
  49. fax_countryCode: yup.string().min(3, displayErrorMsg(intl.formatMessage({id: 'requireDialingCode'}))).nullable(),
  50. tel_countryCode: yup.string().min(3, displayErrorMsg(intl.formatMessage({id: 'requireDialingCode'}))),
  51. phoneNumber: yup.string().min(8, displayErrorMsg(intl.formatMessage({id: 'requiredValidNumber'}))).required(displayErrorMsg(intl.formatMessage({id: 'requireContactNumber'}))),
  52. faxNumber: yup.string().min(8, displayErrorMsg(intl.formatMessage({id: 'require8Number'}))).nullable(),
  53. brExpiryDate: yup.string().min(8).required(displayErrorMsg(intl.formatMessage({id: 'pleaseFillInBusinessRegCertValidityDate'}))),
  54. brNo: yup.string().required(displayErrorMsg(intl.formatMessage({id: 'pleaseFillInBusinessRegCertNumber'}))).test('checkBrNoFormat', displayErrorMsg(displayErrorMsg(intl.formatMessage({id: 'pleaseFillInValidBusinessRegCertNumber'}))), function (value) {
  55. var brNo_pattern = /[0-9]{8}/
  56. if (value !== undefined) {
  57. if (value.match(brNo_pattern)) {
  58. return true
  59. } else {
  60. return false
  61. }
  62. }
  63. }),
  64. }),
  65. onSubmit: vaule => {
  66. console.log(vaule)
  67. HttpUtils.post({
  68. url: UrlUtils.POST_ORG_SAVE_PATH,
  69. params: {
  70. id: id > 0 ? id : null,
  71. enCompanyName: vaule.enCompanyName,
  72. chCompanyName: vaule.chCompanyName,
  73. brNo: vaule.brNo,
  74. brExpiryDate: vaule.brExpiryDate,
  75. enCompanyNameTemp: vaule.enCompanyNameTemp,
  76. chCompanyNameTemp: vaule.chCompanyNameTemp,
  77. brExpiryDateTemp: vaule.brExpiryDateTemp,
  78. contactPerson: vaule.contactPerson,
  79. contactTel: {
  80. countryCode: vaule.tel_countryCode,
  81. phoneNumber: vaule.phoneNumber
  82. },
  83. faxNo: {
  84. countryCode: vaule.fax_countryCode,
  85. faxNumber: vaule.faxNumber
  86. },
  87. addressTemp: {
  88. country: vaule.country,
  89. district: vaule.district,
  90. addressLine1: vaule.addressLine1,
  91. addressLine2: vaule.addressLine2,
  92. addressLine3: vaule.addressLine3,
  93. },
  94. //creditor: vaule.creditor,
  95. },
  96. onSuccess: function () {
  97. notifySaveSuccess()
  98. loadDataFun();
  99. setEditMode(false);
  100. }
  101. });
  102. }
  103. });
  104. useEffect(()=>{
  105. setEditModeFun(editMode);
  106. },[editMode]);
  107. useEffect(() => {
  108. if (Object.keys(userData).length > 0) {
  109. setCreateMode(id <= 0);
  110. setEditMode(id <= 0);
  111. setCurrentUserData(userData);
  112. }
  113. }, [userData]);
  114. // useEffect(() => {
  115. // if (Object.keys(userData).length > 0) {
  116. // if(userData.creditor === undefined||userData.creditor === null){
  117. // userData.creditor = false
  118. // }
  119. // setCurrentUserData(userData);
  120. // }
  121. // }, []);
  122. const onEditClick = () => {
  123. setEditMode(true);
  124. };
  125. const markAsCreditor = () => {
  126. setCreditorConfirmPopUp(false);
  127. HttpUtils.get({
  128. url: UrlUtils.GET_ORG_MARK_AS_CREDITOR + "/" + id,
  129. onSuccess: () => {
  130. loadDataFun();
  131. }
  132. });
  133. }
  134. const markAsNonCreditor = () => {
  135. setNonCreditorConfirmPopUp(false);
  136. HttpUtils.get({
  137. url: UrlUtils.GET_ORG_MARK_AS_NON_CREDITOR + "/" + id,
  138. onSuccess: () => {
  139. loadDataFun();
  140. }
  141. });
  142. }
  143. return (
  144. <MainCard elevation={0}
  145. border={false}
  146. content={false}
  147. >
  148. <form onSubmit={formik.handleSubmit} style={{ padding: 24 }}>
  149. {/*top*/}
  150. <Grid item s={12} md={12} lg={12} sx={{ mb: 3 }} alignItems={"start"} justifyContent="center">
  151. <Grid container maxWidth justifyContent="flex-start">
  152. {editMode ?
  153. <>
  154. {createMode ?
  155. <>
  156. <Grid item sx={{ ml: 0, mr: 3 }}>
  157. <Button
  158. size="large"
  159. variant="contained"
  160. type="submit"
  161. sx={{
  162. textTransform: 'capitalize',
  163. alignItems: 'end'
  164. }}
  165. >
  166. <Typography variant="h5">Create</Typography>
  167. </Button>
  168. </Grid>
  169. </> :
  170. <>
  171. <Grid item sx={{ ml: 0, mr: 3 }}>
  172. <Button
  173. size="large"
  174. variant="contained"
  175. onClick={loadDataFun}
  176. sx={{
  177. textTransform: 'capitalize',
  178. alignItems: 'end'
  179. }}
  180. >
  181. <Typography variant="h5">Reset & Back</Typography>
  182. </Button>
  183. </Grid>
  184. <Grid item sx={{ ml: 3, mr: 3 }}>
  185. <Button
  186. size="large"
  187. variant="contained"
  188. type="submit"
  189. color="success"
  190. sx={{
  191. textTransform: 'capitalize',
  192. alignItems: 'end'
  193. }}
  194. >
  195. <Typography variant="h5">Save</Typography>
  196. </Button>
  197. </Grid>
  198. </>
  199. }
  200. </>
  201. :
  202. <>
  203. <Grid item sx={{ ml: 0, mr: 3 }}>
  204. <Button
  205. size="large"
  206. variant="contained"
  207. sx={{
  208. textTransform: 'capitalize',
  209. alignItems: 'end'
  210. }}
  211. onClick={onEditClick}
  212. >
  213. <Typography variant="h5">Edit</Typography>
  214. </Button>
  215. </Grid>
  216. <Grid item sx={{ ml: 3, mr: 3 }}>
  217. <Button
  218. size="large"
  219. variant="contained"
  220. color="orange"
  221. onClick={()=>setCreditorConfirmPopUp(true)}
  222. sx={{
  223. textTransform: 'capitalize',
  224. alignItems: 'end'
  225. }}
  226. >
  227. <Typography variant="h5">Mark as Creditor</Typography>
  228. </Button>
  229. </Grid>
  230. <Grid item sx={{ ml: 3, mr: 3 }}>
  231. <Button
  232. size="large"
  233. variant="contained"
  234. color="error"
  235. onClick={()=>setNonCreditorConfirmPopUp(true)}
  236. sx={{
  237. textTransform: 'capitalize',
  238. alignItems: 'end'
  239. }}
  240. >
  241. <Typography variant="h5">Mark as Non-Creditor</Typography>
  242. </Button>
  243. </Grid>
  244. </>
  245. }
  246. </Grid>
  247. </Grid>
  248. {/*top*/}
  249. {!onReady ?
  250. <LoadingComponent />
  251. :
  252. <Grid container spacing={1}>
  253. <Grid item xs={12}>
  254. <Typography variant="h4" sx={{ mb: 2, mr: 3, borderBottom: "1px solid black" }}>
  255. Organisation Details
  256. </Typography>
  257. </Grid>
  258. <Grid item lg={4} >
  259. {FieldUtils.getTextField({
  260. label: FieldUtils.notNullFieldLabel("BR No.:"),
  261. valueName: "brNo",
  262. disabled: (!editMode && !createMode),
  263. form: formik
  264. })}
  265. </Grid>
  266. <Grid item lg={4} >
  267. <FormControlLabel
  268. control={<Checkbox checked={formik.values.creditor} />}
  269. label="is Creditor"
  270. name="creditor"
  271. onChange={() => {
  272. formik.setFieldValue("creditor", !formik.values.creditor);
  273. }}
  274. disabled={true}
  275. //disabled={!editMode && !createMode}
  276. />
  277. </Grid>
  278. <Grid item lg={4} ></Grid>
  279. <Grid item lg={4} >
  280. {FieldUtils.getTextField({
  281. label: FieldUtils.notNullFieldLabel("Name (Eng):"),
  282. valueName: "enCompanyName",
  283. disabled: (!editMode && !createMode),
  284. form: formik
  285. })}
  286. </Grid>
  287. <Grid item lg={4} >
  288. {FieldUtils.getTextField({
  289. label: "Name (Ch):",
  290. valueName: "chCompanyName",
  291. disabled: (!editMode && !createMode),
  292. form: formik
  293. })}
  294. </Grid>
  295. <Grid item lg={4} >
  296. {FieldUtils.getDateField({
  297. label: FieldUtils.notNullFieldLabel("Expiry Date:"),
  298. valueName: "brExpiryDate",
  299. disabled: (!editMode && !createMode),
  300. form: formik
  301. })}
  302. </Grid>
  303. <Grid item lg={4} >
  304. {FieldUtils.getTextField({
  305. label: FieldUtils.notNullFieldLabel("Contact Person:"),
  306. valueName: "contactPerson",
  307. disabled: (!editMode && !createMode),
  308. form: formik
  309. })}
  310. </Grid>
  311. <Grid item lg={4} >
  312. {FieldUtils.getPhoneField({
  313. label: FieldUtils.notNullFieldLabel("Contact Tel:"),
  314. valueName: {
  315. code: "tel_countryCode",
  316. num: "phoneNumber"
  317. },
  318. disabled: (!editMode && !createMode),
  319. form: formik
  320. })}
  321. </Grid>
  322. <Grid item lg={4} >
  323. {FieldUtils.getPhoneField({
  324. label: "Fax No:",
  325. valueName: {
  326. code: "fax_countryCode",
  327. num: "faxNumber"
  328. },
  329. disabled: (!editMode && !createMode),
  330. form: formik
  331. })}
  332. </Grid>
  333. <Grid item lg={4} >
  334. {FieldUtils.getComboField({
  335. label: FieldUtils.notNullFieldLabel("Country:"),
  336. valueName: "country",
  337. disabled: (!editMode && !createMode),
  338. dataList: ComboData.country,
  339. getOptionLabel: (option) => option.type? intl.formatMessage({ id: option.type }) : "",
  340. form: formik
  341. })}
  342. </Grid>
  343. <Grid item lg={4} >
  344. {FieldUtils.getComboField({
  345. label: FieldUtils.notNullFieldLabel("District:"),
  346. valueName: "district",
  347. disabled: (!editMode && !createMode),
  348. dataList: ComboData.district,
  349. getOptionLabel: (option) => option.type? intl.formatMessage({ id: option.type }) : "",
  350. form: formik
  351. })}
  352. </Grid>
  353. <Grid item lg={4} >
  354. {FieldUtils.getAddressField({
  355. label: FieldUtils.notNullFieldLabel("Address:"),
  356. valueName: ["addressLine1", "addressLine2", "addressLine3"],
  357. disabled: (!editMode && !createMode),
  358. form: formik
  359. })}
  360. </Grid>
  361. <Grid item lg={12} ></Grid>
  362. </Grid>
  363. }
  364. </form>
  365. <div>
  366. <Dialog open={creditorConfirmPopUp} onClose={() => setCreditorConfirmPopUp(false)} >
  367. <DialogTitle><Typography variant="h3">Confirm</Typography></DialogTitle>
  368. <DialogContent style={{ display: 'flex', }}>
  369. <Typography variant="h4" style={{ padding: '16px' }}>Are you sure mark as Creditor?</Typography>
  370. </DialogContent>
  371. <DialogActions>
  372. <Button onClick={() => setCreditorConfirmPopUp(false)}><Typography variant="h5">Cancel</Typography></Button>
  373. <Button onClick={() => markAsCreditor()}><Typography variant="h5">Confirm</Typography></Button>
  374. </DialogActions>
  375. </Dialog>
  376. </div>
  377. <div>
  378. <Dialog open={nonCreditorConfirmPopUp} onClose={() => setNonCreditorConfirmPopUp(false)} >
  379. <DialogTitle><Typography variant="h3">Confirm</Typography></DialogTitle>
  380. <DialogContent style={{ display: 'flex', }}>
  381. <Typography variant="h4" style={{ padding: '16px' }}>Are you sure mark as Non-Creditor?</Typography>
  382. </DialogContent>
  383. <DialogActions>
  384. <Button onClick={() => setNonCreditorConfirmPopUp(false)}><Typography variant="h5">Cancel</Typography></Button>
  385. <Button onClick={() => markAsNonCreditor()}><Typography variant="h5">Confirm</Typography></Button>
  386. </DialogActions>
  387. </Dialog>
  388. </div>
  389. </MainCard>
  390. );
  391. };
  392. export default OrganizationCard;