Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
hyuna committed Aug 20, 2024
2 parents 45d8225 + 70a076c commit 092a048
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 96 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
2 changes: 1 addition & 1 deletion src/app/components/common/list/changeClass/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const ChangeClass: React.FC<ChangeClassProps> = ({
>
<div className="text-Button-L text-neutral-50">{student}</div>
<div className="flex gap-4 text-Button-L text-neutral-50">
<p className=" w-8">{prevClass}</p>
<p className=" w-28">{prevClass}</p>
<Image src={nextArrow} alt="" />
<p className=" w-28 flex justify-center">{nextClass}</p>
</div>
Expand Down
1 change: 0 additions & 1 deletion src/app/selfStudyCheck/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ const SelfStudyCheck = () => {
localStorage.removeItem(key);
}
});
Check();
}, [selectedClass, selectedGrade]);

const handleGradeChange = (selectedOption: number) => {
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;
Loading

0 comments on commit 092a048

Please sign in to comment.