Skip to content

Commit

Permalink
출석체크 수정
Browse files Browse the repository at this point in the history
출석체크 수정
  • Loading branch information
phyuna0525 authored Aug 20, 2024
2 parents 995d57f + 7db4c6b commit a1827dd
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 94 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"swr": "^2.2.4",
"tailwind": "^4.0.0",
"tailwind-scrollbar-hide": "^1.1.7",
"uuid": "^9.0.1"
"uuid": "^9.0.1",
"zustand": "^4.5.4"
},
"devDependencies": {
"@types/node": "^20",
Expand Down
6 changes: 4 additions & 2 deletions src/apis/afterManage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import apiError from "@/hook/apiError";
export const After = (param: Type) => {
const { handleError } = apiError();
return useQuery({
queryKey: ["After"],
queryKey: ["After", param],
queryFn: async () => {
try {
await instance.post("after", {
Expand Down Expand Up @@ -116,7 +116,9 @@ export const GetClubList = (club: string) => {
queryKey: ["GetClubList", club],
queryFn: async () => {
try {
const response = await instance.get(`/attendance/club?club=${club}`);
const response = await instance.get(
`/attendance/alltime/club?club=${club}`
);
return response.data;
} catch (error) {
handleError(error);
Expand Down
4 changes: 2 additions & 2 deletions src/apis/selfStudy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const CheckStatus = () => {
return useMutation<void, Error, Change[]>({
mutationFn: async (param) => {
try {
await instance.patch(`/attendance/modify`, param);
await instance.patch(`/attendance/alltime/modify`, param);
} catch (error) {
handleError(error);
}
Expand All @@ -39,7 +39,7 @@ export const ClassStudentCheck = () => {
mutationFn: async (param) => {
try {
const response = await instance.get(
`/attendance/grade?grade=${param.grade}&class_num=${param.class}`
`/attendance/alltime/grade?grade=${param.grade}&class_num=${param.class}`
);
return response.data;
} catch (error) {
Expand Down
34 changes: 14 additions & 20 deletions src/apis/weekendMeal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,39 +78,33 @@ export const GetAllStudentMeal = () => {
});
};

export const MealCheck = () => {
export const MealCheck = (grade: number, class_num: number) => {
const { handleError } = apiError();
return useMutation<
mealcheckProp[],
Error,
{ grade: number; class_num: number }
>({
mutationFn: async (param) => {
return useQuery({
queryKey: ["MealCheck", grade, class_num],
queryFn: async () => {
try {
const response = await instance.get(
`/weekend-meal/all?grade=${param.grade}&class_num=${param.class_num}`
const { data } = await instance.get<mealcheckProp[]>(
`/weekend-meal/all?grade=${grade}&class_num=${class_num}`
);
return response.data;
return data;
} catch (error) {
handleError(error);
}
},
});
};

export const NotMealCheck = () => {
export const NotMealCheck = (grade: number, class_num: number) => {
const { handleError } = apiError();
return useMutation<
notCheckMeal[],
Error,
{ grade: number; class_num: number }
>({
mutationFn: async (param) => {
return useQuery({
queryKey: ["NotMealCheck", grade, class_num],
queryFn: async () => {
try {
const response = await instance.get(
`/weekend-meal/quit?grade=${param.grade}&class_num=${param.class_num}`
const { data } = await instance.get<notCheckMeal[]>(
`/weekend-meal/quit?grade=${grade}&class_num=${class_num}`
);
return response.data;
return data;
} catch (error) {
handleError(error);
}
Expand Down
69 changes: 8 additions & 61 deletions src/app/WeekendMeals/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ interface notCheckMeal {

const WeekendMeals: NextPage = () => {
const router = useRouter();
const [checkMeal, setCheckMeal] = useState<mealcheckProp[]>([]);
const [notCheckMeal, setNotCheckMeal] = useState<notCheckMeal[]>([]);
const [selectGrade, setSelectGrade] = useState<number>(1);
const [selectClass, setSelectClass] = useState<number>(1);
const [effect, setEffect] = useState<number>(0);
Expand All @@ -42,24 +40,12 @@ const WeekendMeals: NextPage = () => {
router.push("/WeekendMeals/all");
};

const { mutate: checkMealMutate } = MealCheck();
const { mutate: notCheckMealMutate } = NotMealCheck();

useEffect(() => {
checkMealList();
notCheckMealList();
}, [selectGrade, selectClass]);

useEffect(() => {
const timer = setTimeout(() => {
notCheckMealList();
checkMealList();
}, 100);

return () => {
clearTimeout(timer);
};
}, [effect]);
const { data: checkMealMutate, refetch: RecheckMealMutate } = MealCheck(
selectGrade,
selectClass
);
const { data: notCheckMealMutate, refetch: RenotCheckMealMutate } =
NotMealCheck(selectGrade, selectClass);

useEffect(() => {
const grade = parseInt(localStorage.getItem("grade") || "1", 10);
Expand All @@ -78,45 +64,6 @@ const WeekendMeals: NextPage = () => {
setSelectClass(selectedOption);
};

const checkMealList = async () => {
try {
await checkMealMutate(
{ grade: selectGrade, class_num: selectClass },
{
onSuccess: (data) => {
setCheckMeal(data);
},
onError: (error) => {
console.log(error);
},
}
);
} catch (error) {
console.log(error);
}
};

const notCheckMealList = async () => {
try {
await notCheckMealMutate(
{
grade: selectGrade,
class_num: selectClass,
},
{
onSuccess: (data) => {
setNotCheckMeal(data);
},
onError: (error) => {
console.log(error);
},
}
);
} catch (error) {
console.log(error);
}
};

return (
<BackGround
subTitle="주말 급식"
Expand Down Expand Up @@ -154,7 +101,7 @@ const WeekendMeals: NextPage = () => {
</div>
</div>
<div className=" flex flex-col gap-3">
{checkMeal?.map((item, index) => (
{checkMealMutate?.map((item, index) => (
<Classmeals
key={index}
number={setStudentNum(item)}
Expand All @@ -174,7 +121,7 @@ const WeekendMeals: NextPage = () => {
</div>
</div>
<div className="flex flex-col gap-3 h-full">
{notCheckMeal?.map((item, index) => (
{notCheckMealMutate?.map((item, index) => (
<Classmeals
id={item.id}
key={index}
Expand Down
38 changes: 38 additions & 0 deletions src/stores/useChangeStatus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import create from "zustand";

interface Student {
user_id: string;
status: string;
}

interface AttendanceStore {
students: Student[];
addStudent: (user_id: string, status?: string) => void;
updateStatus: (user_id: string, status: string) => void;
getStatus: (user_id: string) => string | undefined;
}

const useAttendanceStore = create<AttendanceStore>((set, get) => ({
students: [],

addStudent: (user_id, status = "ATTENDANCE") => {
set((state) => ({
students: [...state.students, { user_id, status }],
}));
},

updateStatus: (user_id, status) => {
set((state) => ({
students: state.students.map((student) =>
student.user_id === user_id ? { ...student, status } : student
),
}));
},

getStatus: (user_id) => {
return get().students.find((student) => student.user_id === user_id)
?.status;
},
}));

export default useAttendanceStore;
78 changes: 70 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,19 @@
dependencies:
"@tanstack/query-core" "5.24.1"

"@types/cookie@^0.6.0":
version "0.6.0"
resolved "https://registry.yarnpkg.com/@types/cookie/-/cookie-0.6.0.tgz#eac397f28bf1d6ae0ae081363eca2f425bedf0d5"
integrity sha512-4Kh9a6B2bQciAhf7FSuMRRkUWecJgJu9nPnx3yzpsfXX/c50REIqpHY4C82bXP90qrLtXtkDxTZosYO3UpOwlA==

"@types/hoist-non-react-statics@^3.3.5":
version "3.3.5"
resolved "https://registry.yarnpkg.com/@types/hoist-non-react-statics/-/hoist-non-react-statics-3.3.5.tgz#dab7867ef789d87e2b4b0003c9d65c49cc44a494"
integrity sha512-SbcrWzkKBw2cdwRTwQAswfpB9g9LJWfjtUeW/jvNwbhC8cpmmNYVePa+ncbUe0rGTQ7G3Ff6mYUN2VMfLVr+Sg==
dependencies:
"@types/react" "*"
hoist-non-react-statics "^3.3.0"

"@types/json5@^0.0.29":
version "0.0.29"
resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee"
Expand Down Expand Up @@ -949,6 +962,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.3.1.tgz#e7e0a1f9ef43b4c8ba925c5c5a96e806d16873bb"
integrity sha512-+IJOX0OqlHCszo2mBUq+SrEbCj6w7Kpffqx60zYbPTFaO4+yYgRjHwcZNpWvaTylDHaV7PPmBHzSecZiMhtPgw==

cookie@^0.6.0:
version "0.6.0"
resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.6.0.tgz#2798b04b071b0ecbff0dbb62a505a8efa4e19051"
integrity sha512-U71cyTamuh1CRNCfpGY6to28lxvNwPG4Guz/EVjgf3Jmzv0vlDp1atT9eS5dDjMYHucpHbWns6Lwf3BKz6svdw==

core-js@^2.4.0:
version "2.6.12"
resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.6.12.tgz#d9333dfa7b065e347cc5682219d6f690859cc2ec"
Expand Down Expand Up @@ -1891,6 +1909,13 @@ hasown@^2.0.0:
dependencies:
function-bind "^1.1.2"

hoist-non-react-statics@^3.3.0, hoist-non-react-statics@^3.3.2:
version "3.3.2"
resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-3.3.2.tgz#ece0acaf71d62c2969c2ec59feff42a4b1a85b45"
integrity sha512-/gGivxi8JPKWNm/W0jSmzcMPpfpPLc3dY/6GxhX2hQ9iGj3aDfklV4ET7NjKpSinLpJ5vafa9iiGIEZg10SfBw==
dependencies:
react-is "^16.7.0"

[email protected], http-errors@~1.6.2, http-errors@~1.6.3:
version "1.6.3"
resolved "https://registry.yarnpkg.com/http-errors/-/http-errors-1.6.3.tgz#8b55680bb4be283a0b5bf4ea2e38580be1d9320d"
Expand Down Expand Up @@ -2951,7 +2976,7 @@ [email protected]:
iconv-lite "0.4.23"
unpipe "1.0.0"

react-calendar@*, react-calendar@^4.8.0:
react-calendar@*:
version "4.8.0"
resolved "https://registry.yarnpkg.com/react-calendar/-/react-calendar-4.8.0.tgz#61edbba6d17e7ef8a8012de9143b5e5ff41104c8"
integrity sha512-qFgwo+p58sgv1QYMI1oGNaop90eJVKuHTZ3ZgBfrrpUb+9cAexxsKat0sAszgsizPMVo7vOXedV7Lqa0GQGMvA==
Expand All @@ -2962,6 +2987,15 @@ react-calendar@*, react-calendar@^4.8.0:
prop-types "^15.6.0"
warning "^4.0.0"

react-cookie@^7.1.4:
version "7.2.0"
resolved "https://registry.yarnpkg.com/react-cookie/-/react-cookie-7.2.0.tgz#5770cd8d6b3c60c5d34ec4b7926f90281aee22ae"
integrity sha512-mqhPERUyfOljq5yJ4woDFI33bjEtigsl8JDJdPPeNhr0eSVZmBc/2Vdf8mFxOUktQxhxTR1T+uF0/FRTZyBEgw==
dependencies:
"@types/hoist-non-react-statics" "^3.3.5"
hoist-non-react-statics "^3.3.2"
universal-cookie "^7.0.0"

react-dom@^18:
version "18.2.0"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-18.2.0.tgz#22aaf38708db2674ed9ada224ca4aa708d821e3d"
Expand All @@ -2970,7 +3004,7 @@ react-dom@^18:
loose-envify "^1.1.0"
scheduler "^0.23.0"

react-is@^16.13.1:
react-is@^16.13.1, react-is@^16.7.0:
version "16.13.1"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"
integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==
Expand Down Expand Up @@ -3304,8 +3338,16 @@ streamsearch@^1.1.0:
resolved "https://registry.yarnpkg.com/streamsearch/-/streamsearch-1.1.0.tgz#404dd1e2247ca94af554e841a8ef0eaa238da764"
integrity sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==

"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0:
name string-width-cjs
"string-width-cjs@npm:string-width@^4.2.0":
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
dependencies:
emoji-regex "^8.0.0"
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"

string-width@^4.1.0:
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
Expand Down Expand Up @@ -3386,8 +3428,14 @@ [email protected]:
is-obj "^1.0.1"
is-regexp "^1.0.0"

"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
name strip-ansi-cjs
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
dependencies:
ansi-regex "^5.0.1"

strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
Expand Down Expand Up @@ -3669,6 +3717,14 @@ undici-types@~5.26.4:
resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617"
integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==

universal-cookie@^7.0.0:
version "7.2.0"
resolved "https://registry.yarnpkg.com/universal-cookie/-/universal-cookie-7.2.0.tgz#1f3fa9c575d863ac41b4e42272d240ae2d32c047"
integrity sha512-PvcyflJAYACJKr28HABxkGemML5vafHmiL4ICe3e+BEKXRMt0GaFLZhAwgv637kFFnnfiSJ8e6jknrKkMrU+PQ==
dependencies:
"@types/cookie" "^0.6.0"
cookie "^0.6.0"

[email protected]:
version "2.2.0"
resolved "https://registry.yarnpkg.com/unload/-/unload-2.2.0.tgz#ccc88fdcad345faa06a92039ec0f80b488880ef7"
Expand Down Expand Up @@ -3702,7 +3758,7 @@ uri-js@^4.2.2:
dependencies:
punycode "^2.1.0"

use-sync-external-store@^1.2.0:
use-sync-external-store@1.2.0, use-sync-external-store@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/use-sync-external-store/-/use-sync-external-store-1.2.0.tgz#7dbefd6ef3fe4e767a0cf5d7287aacfb5846928a"
integrity sha512-eEgnFxGQ1Ife9bzYs6VLi8/4X6CObHMw9Qr9tPY43iKwsPw8xE8+EFsf/2cFZ5S3esXgpWgtSCtLNS41F+sKPA==
Expand Down Expand Up @@ -3868,4 +3924,10 @@ yocto-queue@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b"
integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==


zustand@^4.5.4:
version "4.5.4"
resolved "https://registry.yarnpkg.com/zustand/-/zustand-4.5.4.tgz#63abdd81edfb190bc61e0bbae045cc4d52158a05"
integrity sha512-/BPMyLKJPtFEvVL0E9E9BTUM63MNyhPGlvxk1XjrfWTUlV+BR8jufjsovHzrtR6YNcBEcL7cMHovL1n9xHawEg==
dependencies:
use-sync-external-store "1.2.0"

0 comments on commit a1827dd

Please sign in to comment.