Skip to content

Commit

Permalink
refactor(manager): 조회가 안될 시 정원을 모두 0으로 나오게 한다.(#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
loopy-lim authored Apr 10, 2024
2 parents 701acbe + 5676d48 commit 36a095e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
19 changes: 11 additions & 8 deletions service-manager/src/components/apply-list/ApplyCount.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Txt } from '@quokka/design-system';
import { useAllRegistrationQuery } from '../../hooks/react-query/useRegistration';
import { useSectorQueryById } from '../../hooks/react-query/useSetting';
import {
useSectorQueryById,
useSectorsQuery,
} from '../../hooks/react-query/useSetting';

interface ApplyCountProps {
eventId: string;
Expand All @@ -10,9 +13,8 @@ interface ApplyCountProps {
export const ApplyCount = ({ eventId, sector }: ApplyCountProps) => {
const { sectorSettingData } = useSectorQueryById(eventId);
const { registrations } = useAllRegistrationQuery(eventId);
const applicantNumber = registrations?.filter(
(data) => data.sectorNum === sector,
);
const applicantNumber =
registrations?.filter((data) => data.sectorNum === sector) ?? 0;
const limit = sectorSettingData?.find((data) => data.sectorNumber === sector);

return (
Expand All @@ -21,12 +23,13 @@ export const ApplyCount = ({ eventId, sector }: ApplyCountProps) => {
{`구간정원: ${Math.min(
applicantNumber.length,
limit?.reserve ?? 0,
)}명 / ${limit?.reserve}명`}
)}명 / ${limit?.reserve ?? 0}명`}
</Txt>
<Txt size="h6" color="black">
{`예비정원: ${Math.abs(
registrations.length - (limit?.reserve ?? 0),
)}명 / ${limit?.sectorCapacity}명`}
{`예비정원: ${Math.max(
applicantNumber.length - (limit?.reserve ?? 0),
0,
)}명 / ${limit?.sectorCapacity ?? 0}명`}
</Txt>
</div>
);
Expand Down
7 changes: 6 additions & 1 deletion service-manager/src/components/apply-list/ApplyList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import { useAllRegistrationQuery } from '../../hooks/react-query/useRegistration
import { useState } from 'react';
import { ApplyCount } from './ApplyCount';
import { useSectorQueryById } from '../../hooks/react-query/useSetting';
export const ApplyList = ({ eventId }: { eventId: string }) => {

interface ApplyListProps {
eventId: string;
}

export const ApplyList = ({ eventId }: ApplyListProps) => {
const { registrations } = useAllRegistrationQuery(eventId);
const sectors = Array.from(
new Set(registrations.map((registration) => registration.sectorNum)),
Expand Down
2 changes: 1 addition & 1 deletion service-manager/src/hooks/react-query/useSetting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const useSectorsQuery = () => {
refetchOnWindowFocus: false,
});

return { sectorSettingData: data };
return { sectors: data };
};

export const useSectorQueryById = (eventId: string) => {
Expand Down

0 comments on commit 36a095e

Please sign in to comment.