Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 0.6.0: 연동 관리 기능 개발 #76

Merged
merged 10 commits into from
Nov 8, 2023
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "dutying-web",
"private": true,
"version": "0.5.0",
"version": "0.6.0",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
15 changes: 15 additions & 0 deletions src/assets/svg/SuccessCircleIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { SVGProps } from 'react';
const SvgSuccessCircleIcon = (props: SVGProps<SVGSVGElement>) => (
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 60 60" {...props}>
<circle cx={30} cy={30} r={30} fill="#EDE4FF" />
<circle cx={30} cy={30} r={23} fill="#844AFF" stroke="#844AFF" strokeWidth={2} />
<path
stroke="#fff"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={4}
d="m20 30.75 6.667 8.75L40 22"
/>
</svg>
);
export default SvgSuccessCircleIcon;
1 change: 1 addition & 0 deletions src/assets/svg/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,4 @@ export { default as UncheckedIcon } from './UncheckedIcon';
export { default as UncheckedIcon2 } from './UncheckedIcon2';
export { default as UnlinkedIcon } from './UnlinkedIcon';
export { default as XIcon } from './XIcon';
export { default as SuccessCircleIcon } from './SuccessCircleIcon';
26 changes: 11 additions & 15 deletions src/hooks/auth/useAuth/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { shallow } from 'zustand/shallow';
import useAuthStore from './store';
import axiosInstance from '@libs/api/client';
import { useMutation } from '@tanstack/react-query';
import { demoStart, getAccountMe } from '@libs/api/auth';
import { useNavigate } from 'react-router';
import ROUTE from '@libs/constant/path';
Expand Down Expand Up @@ -48,24 +47,21 @@ const useAuth = (activeEffect = false) => {
setState('isAuth', true);
setState('accessToken', accessToken);
initEditShiftStore();
sendEvent(events.auth.login);
axiosInstance.defaults.headers.common['Authorization'] = `Bearer ${accessToken}`;
navigate(nextPageUrl || '/make');
location.replace(nextPageUrl || '/make');
sendEvent(events.auth.login);
};

const { mutate: demoTry } = useMutation(demoStart(), {
onSuccess: (data) => {
handleLogin(data.accessToken);
setState('accessToken', data.accessToken);
setState('accountId', data.accountResDto.accountId);
setState('nurseId', data.accountResDto.nurseId);
setState('wardId', data.accountResDto.wardId);
setState('isAuth', true);
setState('demoStartDate', new Date());
navigate(ROUTE.MAKE);
},
});
const demoTry = async () => {
const data = await demoStart();
setState('accessToken', data.accessToken);
setState('accountId', data.accountResDto.accountId);
setState('nurseId', data.accountResDto.nurseId);
setState('wardId', data.accountResDto.wardId);
setState('isAuth', true);
setState('demoStartDate', new Date());
navigate(ROUTE.MAKE);
};

const handleGetAccountMe = async () => {
const account = await getAccountMe();
Expand Down
6 changes: 6 additions & 0 deletions src/hooks/shift/useEditShift/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,12 @@ const useEditShift = (activeEffect = false) => {
const changeFocusedShift = useCallback(
(shiftTypeId: number | null) => {
if (!wardId || !focus || !shift) return;
console.log(
shift.divisionShiftNurses
.flatMap((x) => x)
.find((x) => x.shiftNurse.shiftNurseId === focus.shiftNurseId)!.wardShiftList[focus.day],
shiftTypeId
);
if (
shift.divisionShiftNurses
.flatMap((x) => x)
Expand Down
155 changes: 85 additions & 70 deletions src/hooks/ward/useEditShiftTeam/index.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,14 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import {
UpdateNurseDTO,
updateNurse as patchNurse,
updateNurseOrder,
updateNurseShiftType,
updateNurseShiftTypeRequest,
updateShiftTeamDivision,
} from '@libs/api/nurse';
import useEditNurseStore from './store';
import * as nurseApi from '@libs/api/nurse';
import * as shiftTeamApi from '@libs/api/shiftTeam';
import { shallow } from 'zustand/shallow';
import {
UpdateShiftTeamDTO,
addNurseIntoShiftTeam,
createShiftTeam,
deleteShiftTeam,
removeNurseFromShiftTeam,
updateShiftTeam,
} from '@libs/api/shiftTeam';
import { getWard } from '@libs/api/ward';
import { produce } from 'immer';
import useEditNurseStore from './store';
import useEditShift from '@hooks/shift/useEditShift';
import useAuth from '@hooks/auth/useAuth';
import useRequestShift from '@hooks/shift/useRequestShift';
import useAuth from '@hooks/auth/useAuth';

const useEditShiftTeam = () => {
const [selectedNurseId, setState] = useEditNurseStore(
Expand All @@ -47,8 +33,8 @@ const useEditShiftTeam = () => {
});

const { mutate: updateNurseMutate } = useMutation(
({ nurseId, updateNurseDTO }: { nurseId: number; updateNurseDTO: UpdateNurseDTO }) =>
patchNurse(nurseId, updateNurseDTO),
({ nurseId, updateNurseDTO }: { nurseId: number; updateNurseDTO: nurseApi.UpdateNurseDTO }) =>
nurseApi.updateNurse(nurseId, updateNurseDTO),
{
onSuccess: () => {
queryClient.invalidateQueries(getWardQueryKey);
Expand All @@ -63,7 +49,7 @@ const useEditShiftTeam = () => {

const { mutate: addNurseMutate } = useMutation(
({ wardId, shiftTeamId }: { wardId: number; shiftTeamId: number }) =>
addNurseIntoShiftTeam(wardId, shiftTeamId, {
shiftTeamApi.addNurseIntoShiftTeam(wardId, shiftTeamId, {
name: `간호사${Math.floor(Math.random() * 10000)}`,
phoneNum: '01012345678',
gender: '여',
Expand All @@ -83,7 +69,7 @@ const useEditShiftTeam = () => {

const { mutate: deleteNurseMutate } = useMutation(
({ wardId, nurseId, shiftTeamId }: { wardId: number; nurseId: number; shiftTeamId: number }) =>
removeNurseFromShiftTeam(wardId, shiftTeamId, nurseId),
shiftTeamApi.removeNurseFromShiftTeam(wardId, shiftTeamId, nurseId),
{
onSuccess: () => queryClient.invalidateQueries(getWardQueryKey),
}
Expand All @@ -97,23 +83,23 @@ const useEditShiftTeam = () => {
}: {
nurseId: number;
nurseShiftTypeId: number;
change: updateNurseShiftTypeRequest;
}) => updateNurseShiftType(nurseId, nurseShiftTypeId, change),
change: nurseApi.updateNurseShiftTypeRequest;
}) => nurseApi.updateNurseShiftType(nurseId, nurseShiftTypeId, change),
{
onSuccess: () => queryClient.invalidateQueries(getWardQueryKey),
}
);

const { mutate: createShiftTeamMutate } = useMutation(
(wardId: number) => createShiftTeam(wardId),
(wardId: number) => shiftTeamApi.createShiftTeam(wardId),
{
onSuccess: () => queryClient.invalidateQueries(getWardQueryKey),
}
);

const { mutate: deleteShiftTeamMutate } = useMutation(
({ wardId, shiftTeamId }: { wardId: number; shiftTeamId: number }) =>
deleteShiftTeam(wardId, shiftTeamId),
shiftTeamApi.deleteShiftTeam(wardId, shiftTeamId),
{
onSuccess: () => queryClient.invalidateQueries(getWardQueryKey),
}
Expand All @@ -130,7 +116,7 @@ const useEditShiftTeam = () => {
prevPriority: number;
changeValue: number;
patchYearMonth: string;
}) => updateShiftTeamDivision(shiftTeamId, prevPriority, changeValue, patchYearMonth),
}) => nurseApi.updateShiftTeamDivision(shiftTeamId, prevPriority, changeValue, patchYearMonth),
{
onSuccess: () => {
queryClient.invalidateQueries(getWardQueryKey);
Expand Down Expand Up @@ -158,7 +144,7 @@ const useEditShiftTeam = () => {
nextPriority: number;
patchYearMonth: string;
}) =>
updateNurseOrder(
nurseApi.updateNurseOrder(
nurseId,
shiftTeamId,
nextShiftTeamId,
Expand Down Expand Up @@ -310,8 +296,8 @@ const useEditShiftTeam = () => {
}: {
wardId: number;
shiftTeamId: number;
updateShiftTeamDTO: UpdateShiftTeamDTO;
}) => updateShiftTeam(wardId, shiftTeamId, updateShiftTeamDTO),
updateShiftTeamDTO: shiftTeamApi.UpdateShiftTeamDTO;
}) => shiftTeamApi.updateShiftTeam(wardId, shiftTeamId, updateShiftTeamDTO),
{
onMutate: ({ shiftTeamId, updateShiftTeamDTO }) => {
const oldWard = queryClient.getQueryData<Ward>(getWardQueryKey);
Expand All @@ -333,6 +319,65 @@ const useEditShiftTeam = () => {
}
);

const addNurse = (shiftTeamId: number) => {
wardId && addNurseMutate({ wardId, shiftTeamId });
};
const deleteNurse = (shiftTeamId: number, nurseId: number) => {
wardId && deleteNurseMutate({ wardId, nurseId, shiftTeamId });
};
const selectNurse = (nurseId: number | null) => {
setState('selectedNurseId', nurseId);
};
const updateNurse = (nurseId: number, updateNurseDTO: nurseApi.UpdateNurseDTO) => {
updateNurseMutate({ nurseId, updateNurseDTO });
};
const updateNurseShift = (
nurseId: number,
nurseShiftTypeId: number,
change: nurseApi.updateNurseShiftTypeRequest
) => {
updateNurseShiftTypeMutate({ nurseId, nurseShiftTypeId, change });
};
const createShiftTeam = () => {
wardId && createShiftTeamMutate(wardId);
};
const deleteShiftTeam = (shiftTeamId: number) => {
wardId && deleteShiftTeamMutate({ wardId, shiftTeamId });
};
const editDivision = (
shiftTeamId: number,
prevPriority: number,
changeValue: number,
patchYearMonth: string
) => {
editDivisionMutate({ shiftTeamId, prevPriority, changeValue, patchYearMonth });
};
const moveNurseOrder = (
nurseId: number,
shiftTeamId: number,
nextShiftTeamId: number,
divisionNum: number,
prevPriority: number,
nextPriority: number,
patchYearMonth: string
) => {
moveNurseOrderMutate({
nurseId,
shiftTeamId,
nextShiftTeamId,
divisionNum,
prevPriority,
nextPriority,
patchYearMonth,
});
};
const updateShiftTeam = (
shiftTeamId: number,
updateShiftTeamDTO: shiftTeamApi.UpdateShiftTeamDTO
) => {
wardId && updateShiftTeamMutate({ wardId, shiftTeamId, updateShiftTeamDTO });
};

return {
state: {
ward,
Expand All @@ -342,46 +387,16 @@ const useEditShiftTeam = () => {
shiftTeams: ward?.shiftTeams,
},
actions: {
addNurse: (shiftTeamId: number) => wardId && addNurseMutate({ wardId, shiftTeamId }),
deleteNurse: (shiftTeamId: number, nurseId: number) =>
wardId && deleteNurseMutate({ wardId, nurseId, shiftTeamId }),
selectNurse: (nurseId: number | null) => setState('selectedNurseId', nurseId),
updateNurse: (nurseId: number, updateNurseDTO: UpdateNurseDTO) =>
updateNurseMutate({ nurseId, updateNurseDTO }),
updateNurseShift: (
nurseId: number,
nurseShiftTypeId: number,
change: updateNurseShiftTypeRequest
) => updateNurseShiftTypeMutate({ nurseId, nurseShiftTypeId, change }),
createShiftTeam: () => wardId && createShiftTeamMutate(wardId),
deleteShiftTeam: (shiftTeamId: number) =>
wardId && deleteShiftTeamMutate({ wardId, shiftTeamId }),
editDivision: (
shiftTeamId: number,
prevPriority: number,
changeValue: number,
patchYearMonth: string
) => editDivisionMutate({ shiftTeamId, prevPriority, changeValue, patchYearMonth }),
moveNurseOrder: (
nurseId: number,
shiftTeamId: number,
nextShiftTeamId: number,
divisionNum: number,
prevPriority: number,
nextPriority: number,
patchYearMonth: string
) =>
moveNurseOrderMutate({
nurseId,
shiftTeamId,
nextShiftTeamId,
divisionNum,
prevPriority,
nextPriority,
patchYearMonth,
}),
updateShiftTeam: (shiftTeamId: number, updateShiftTeamDTO: UpdateShiftTeamDTO) =>
wardId && updateShiftTeamMutate({ wardId, shiftTeamId, updateShiftTeamDTO }),
addNurse,
deleteNurse,
selectNurse,
updateNurse,
updateNurseShift,
createShiftTeam,
deleteShiftTeam,
editDivision,
moveNurseOrder,
updateShiftTeam,
},
};
};
Expand Down
Loading