Skip to content

Commit

Permalink
feat: 대타기록 페이지 및 폼 제작
Browse files Browse the repository at this point in the history
  • Loading branch information
jjjuyoa committed Jun 1, 2023
1 parent b25712e commit ade3c5a
Show file tree
Hide file tree
Showing 7 changed files with 275 additions and 40 deletions.
5 changes: 5 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import MyPageAlbaRecord from "pages/alba/MyPageAlbaRecord";
import AlbaMainPage from "pages/alba/inAlba/AlbaMainPage";
import AlbaAttendance from "pages/alba/inAlba/AlbaAttendance";
import AlbaReplace from "pages/alba/inAlba/AlbaReplace";
import AlbaReplaceForm from "pages/alba/inAlba/AlbaReplaceForm";
import MyPageAlbaRecordCheck from "pages/alba/MyPageAlbaRecordCheck";
import MyPageCertification from "pages/main/MyPageCertification";
import MyPageEdit from "pages/main/MyPageEdit";
Expand Down Expand Up @@ -107,6 +108,10 @@ function App() {
<Route path="/alba_invited" element={<AlbaInvitePage />} />
<Route path="/alba_main/:id/contract" element={<AlbaContract />} />
<Route path="/alba_main/:id/replace" element={<AlbaReplace />} />
<Route
path="/alba_main/:id/replace/form"
element={<AlbaReplaceForm />}
/>
<Route path="/alba_record" element={<MyPageAlbaRecord />} />
<Route
path="/alba_record/:id"
Expand Down
15 changes: 12 additions & 3 deletions src/components/LeftMenuAlba.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ const LeftMenuAlba = (props) => {
const location = useLocation();
const [showSubMenu, setShowSubMenu] = useState(false);
const { companyId } = props;

const handleSubMenuToggle = () => {
setShowSubMenu(!showSubMenu);
};
Expand Down Expand Up @@ -136,10 +137,18 @@ const LeftMenuAlba = (props) => {
</NavLink>

<NavLink
to={`/albatest3`}
className={location.pathname === `/albatest3` ? "active" : ""}
to={`/alba_main/${companyId}/replace`}
className={
location.pathname === `/alba_main/${companyId}/replace/form`
? "active"
: ""
}
>
<MenuItem isActive={location.pathname === `/albatest3`}>
<MenuItem
isActive={
location.pathname === `/alba_main/${companyId}/replace/form`
}
>
대타 기록
</MenuItem>
</NavLink>
Expand Down
4 changes: 2 additions & 2 deletions src/pages/alba/inAlba/AlbaContract.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useDispatch, useSelector } from "react-redux";
import { useLocation, useNavigate, useParams } from "react-router-dom";
import { useState } from "react";

import Header from "components/Header";
import HeaderAlba from "components/HeaderAlba";

import "../../../style/company/companyAlba.scss";
import LeftMenuAlba from "components/LeftMenuAlba";
Expand Down Expand Up @@ -42,7 +42,7 @@ const AlbaContract = (props) => {

return (
<div className="albaList">
<Header />
<HeaderAlba />
<div className="companyAlba-Wrapper">
<LeftMenuAlba companyId={id} />
<div className="list-Wrapper">
Expand Down
24 changes: 17 additions & 7 deletions src/pages/alba/inAlba/AlbaReplace.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useDispatch, useSelector } from "react-redux";
import { useLocation, useNavigate, useParams } from "react-router-dom";
import { useState } from "react";

import Header from "components/Header";
import HeaderAlba from "components/HeaderAlba";
import LeftMenuAlba from "components/LeftMenuAlba";
import "../../../style/alba/albaReplace.scss";

Expand All @@ -17,30 +17,40 @@ const AlbaReplace = () => {

return (
<div className="albaList">
<Header />
<HeaderAlba />
<div className="Alba-Wrapper">
<LeftMenuAlba companyId={id} />
<div className="list-Wrapper">
<div className="title">
<p>대타 기록</p>
<button className="btn_record">기록하기</button>
<button
className="btn_record"
onClick={() => {
navigate(`/alba_main/${id}/replace/form`);
}}
>
기록하기
</button>
</div>
<div className="list">
{alba_replace.map((it) => (
<div className="company_one">
<div className="company_one_right">
<div className="company_set">
<label>기존근무자: </label>
{it.user}
{it.userName}
</div>
<div className="company_set">
<label>대체근무자: </label>
{it.replace_user}
{it.replaceUser}
</div>
<div className="company_set_time">
<label>대타 시간:</label>
{it.time.year}년&nbsp;{it.time.month}월&nbsp;{it.time.date}
{it.checkDate}
<br />
{it.startTime}
{"-"}
{it.endTime}
</div>
</div>
</div>
Expand Down
157 changes: 157 additions & 0 deletions src/pages/alba/inAlba/AlbaReplaceForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
import { useDispatch, useSelector } from "react-redux";
import { useLocation, useNavigate, useParams } from "react-router-dom";
import { useState, useRef } from "react";
import HeaderAlba from "components/HeaderAlba";
import LeftMenuAlba from "components/LeftMenuAlba";
import "../../../style/alba/albaReplace.scss";
import { addReplace } from "../../../redux-toolkit/albaModule/AlbaReplaceSlice";

const AlbaReplaceForm = () => {
const [info, setInfo] = useState({
userName: "김민규",
replaceUser: "",
startTime: "",
endTime: "",
checkDate: "",
});

const dispatch = useDispatch();
const navigate = useNavigate();
const location = useLocation();
const { id } = useParams();

const alba_replace = useSelector((state) => state.alba_replace);

const inputRefs = {
replaceUserInput: useRef(),
startTimeInput: useRef(),
endTimeInput: useRef(),
checkDateInput: useRef(),
};

// const startHandleChange = (e) => {
// const inputTime = e.target.value;
// // 시간 유효성 검사 등을 수행할 수 있습니다.

// console.log(inputTime);
// setInfo(inputTime);
// };
const userHandleChange = (e) => {
{
setInfo((prevInfo) => ({
...prevInfo,
[e.target.name]: e.target.value,
}));
}
};

// const startHandleChange = (e) => {
// const inputTime = e.target.value;
// setInfo((prevInfo) => ({
// ...prevInfo,
// startTime: inputTime,
// }));
// };

// const endHandleChange = (e) => {
// const inputTime = e.target.value;
// setInfo((prevInfo) => ({
// ...prevInfo,
// endTime: inputTime,
// }));
// };

// const dateHandleChange = (e) => {
// const inputTime = e.target.value;
// setInfo((prevInfo) => ({
// ...prevInfo,
// checkDate: inputTime,
// }));
// console.log({ info });
// };

const onClickSave = () => {
if (info.replaceUser === "") {
inputRefs.replaceUserInput.current.focus();
} else if (info.startTime === "") {
inputRefs.startTimeInput.current.focus();
} else if (info.endTime === "") {
inputRefs.endTimeInput.current.focus();
} else if (info.checkDate === "") {
inputRefs.checkDateInput.current.focus();
} else {
dispatch(addReplace(info));
console.log({ info });
navigate(`/alba_main/${id}/replace`);
}
};

return (
<div className="albaList">
<HeaderAlba />
<div className="Alba-Wrapper">
<LeftMenuAlba companyId={id} />
<div className="list-Wrapper">
<div className="title">
<p>대타 기록하기</p>
</div>
<div className="form-Wrapper">
<div className="line">
<label>기존 근무자</label>&nbsp;&nbsp;
{info.userName}
</div>
<div className="line">
<label>대체 근무자</label>
<input
className="input_box"
name="replaceUser"
ref={inputRefs.replaceUserInput}
value={info.replaceUser}
onChange={userHandleChange}
></input>
</div>
<div className="line">
<label>시간 선택</label>
<input
ref={inputRefs.startTimeInput}
className="time"
name="startTime"
type="time"
// pattern="[0-2][0-9]:[0-5][0-9]"
placeholder="00:00"
value={info.startTime}
onChange={userHandleChange}
/>
&nbsp;&nbsp;{"-"}&nbsp;&nbsp;
<input
ref={inputRefs.endTimeInput}
className="time"
name="endTime"
type="time"
// pattern="[0-2][0-9]:[0-5][0-9]"
placeholder="00:00"
value={info.endTime}
onChange={userHandleChange}
/>
</div>
<div className="line">
<label>날짜 선택</label>&nbsp;
<input
ref={inputRefs.checkDateInput}
name="checkDate"
type="date"
value={info.checkDate}
onChange={userHandleChange}
></input>
</div>
<button className="btn_record" onClick={onClickSave}>
기록하기
</button>
</div>
</div>
</div>
</div>
);
};

export default AlbaReplaceForm;
45 changes: 17 additions & 28 deletions src/redux-toolkit/albaModule/AlbaReplaceSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,31 @@ export const AlbaReplaceSlice = createSlice({
name: "alba_replace",
initialState: [
{
user: "김민규",
replace_user: "김정환",
time: {
year: "2023",
month: "04",
date: "11",
start: "07:00",
end: "12:00",
},
userName: "김민규",
replaceUser: "김정환",
startTime: "08:00",
endTime: "13:30",
checkDate: "2023-06-02",
},
{
user: "김민규",
replace_user: "김정환",
time: {
year: "2023",
month: "04",
date: "11",
start: "07:00",
end: "12:00",
},
userName: "김민규",
replaceUser: "김정환",
startTime: "08:00",
endTime: "13:30",
checkDate: "2023-06-02",
},
{
user: "김민규",
replace_user: "김정환",
time: {
year: "2023",
month: "04",
date: "11",
start: "07:00",
end: "12:00",
},
userName: "김민규",
replaceUser: "김정환",
startTime: "08:00",
endTime: "13:30",
checkDate: "2023-06-02",
},
],
reducers: {
addReplace: (state, action) => {
state.push(action.payload);
const nextId = state.length;
state.push({ ...action.payload });
},
},
});
Expand Down
Loading

0 comments on commit ade3c5a

Please sign in to comment.