diff --git a/src/components/basis/group/BaisGroupForm.js b/src/components/basis/group/BaisGroupForm.js index 1dd73a7..d6a2594 100644 --- a/src/components/basis/group/BaisGroupForm.js +++ b/src/components/basis/group/BaisGroupForm.js @@ -1,87 +1,113 @@ -import React, { useState } from 'react'; +import React, { useEffect, useState } from 'react'; +import * as yup from 'yup'; +import { useForm } from 'react-hook-form'; +import classnames from 'classnames'; import { Row, Col, - Table, - Badge, - UncontrolledDropdown, - DropdownMenu, - DropdownItem, - DropdownToggle, Card, - CardHeader, CardBody, - CardTitle, - CardSubtitle, - ButtonGroup, Button, Input, - CustomInput, FormGroup, - Modal, - ModalHeader, - ModalBody, - ModalFooter, - Label + Label, + FormFeedback, + Form } from 'reactstrap'; -import { Link, useHistory } from 'react-router-dom'; +import { yupResolver } from '@hookform/resolvers/yup'; export const BasisGroupForm = props => { + useEffect(() => { + if (props.groupData?.groupId) { + setValue('groupNm', props.groupData?.groupNm); + } + }, [props.groupData]); + + const Schema = yup.object().shape({ + groupNm: yup + .string() + .required('그룹명을 입력해 주세요') + .matches( + /^[ㄱ-힣A-Za-z0-9]{2,12}$/, + '2 자 이상, 12 자 이하 영문자/숫자만 입력 가능합니다.' + ) + }); + + const { register, getValues, setValue, errors, handleSubmit } = useForm({ + defaultValues: { + groupNm: '' + }, + resolver: yupResolver(Schema) + }); + + const onSumbit = async data => { + props.handlerSave(data); + }; + return ( - - - - -
-
-
-

{props.title} 상세정보

-
-
- {props.groupData.type === 'update' ? ( - 최종 수정일자 : {props.groupData.updateDt} - ) : null} +
+ + + + +
+
+
+

{props.title} 상세정보

+
+
+ {props.groupData.type === 'update' ? ( + 최종 수정일자 : {props.groupData.updateDt} + ) : null} +
-
-
-
-
- - - - - - - - - - - - - +
+
+
+ + + + + + + + + + + + {errors && errors.groupNm && ( + + {errors.groupNm.message} + + )} + + - {/* + {/* { */} - -
-
-
+
+
+
+
-
- - 저장 - - {/* - 목록 - */} - {props.groupData.type != 'create' ? ( +
props.handlerWidthrow()} + // onClick={props.handlerSave} + type='submit' > - 삭제 + 저장 - ) : ( - <> - )} + {/* + 목록 + */} + {props.groupData.type != 'create' ? ( + props.handlerWidthrow()} + > + 삭제 + + ) : ( + <> + )} +
-
- - - - + + + + + ); }; diff --git a/src/containers/basis/group/BasisGroupDetailContainer.js b/src/containers/basis/group/BasisGroupDetailContainer.js index 6fa4f1f..8239212 100644 --- a/src/containers/basis/group/BasisGroupDetailContainer.js +++ b/src/containers/basis/group/BasisGroupDetailContainer.js @@ -61,12 +61,32 @@ export const BasisGroupDetailContainer = () => { dispatch(Actions.GROUP_DETAIL.request(id)); }; - const handlerCreate = () => { - dispatch(Actions.GROUP_CREATE.request(groupData)); + const handlerCreate = data => { + const saveData = { + createDt: '', + cstmrSno: groupData.cstmrSno, + groupId: groupData.groupId, + groupNm: data.groupNm, + groupTypeCd: groupData.groupTypeCd, + type: groupData.type, + updateDt: '' + }; + // dispatch(Actions.GROUP_CREATE.request(groupData)); + dispatch(Actions.GROUP_CREATE.request(saveData)); }; - const handlerUpdate = () => { - dispatch(Actions.GROUP_UPDATE.request(groupData)); + const handlerUpdate = data => { + const saveData = { + createDt: groupData.createDt, + cstmrSno: groupData.cstmrSno, + groupId: groupData.groupId, + groupNm: data.groupNm, + groupTypeCd: groupData.groupTypeCd, + type: groupData.type, + updateDt: groupData.updateDt + }; + // dispatch(Actions.GROUP_UPDATE.request(groupData)); + dispatch(Actions.GROUP_UPDATE.request(saveData)); }; const handlerDelete = () => { dispatch(Actions.GROUP_DELETE.request(groupData.groupId)); @@ -81,29 +101,33 @@ export const BasisGroupDetailContainer = () => { return; }; - const handlerInput = e => { - const { name, value } = e.target; - if (name == 'groupNm') { - const regex = /^[ㄱ-힣A-Za-z0-9]{0,11}$/; - if (regex.test(value)) { - setGroupData({ - ...groupData, - [name]: value - }); - } - } + const handlerSave = data => { + groupData.type === 'create' ? handlerCreate(data) : handlerUpdate(data); }; + // const handlerInput = e => { + // const { name, innerRef } = e.target; + // if (name == 'groupNm') { + // // const regex = /^[ㄱ-힣A-Za-z0-9]{0,11}$/; + // // if (regex.test(innerRef)) { + // console.log(innerRef); + // setGroupData({ + // ...groupData, + // [name]: innerRef + // }); + // // } + // } + // }; + return (