Skip to content

Commit

Permalink
Merge pull request #50 from team-crews/feat/goonco
Browse files Browse the repository at this point in the history
[Fix] Fix left trivial issues
  • Loading branch information
Goonco authored Nov 2, 2024
2 parents a5b2c04 + b219f9e commit b7efd4a
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 125 deletions.
64 changes: 34 additions & 30 deletions src/app/apply/[recruitmentCode]/_hooks/use-choice-map.tsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,43 @@
import { useEffect, useState } from 'react';
import { z } from 'zod';
import { RecruitmentSchema } from '../../../../lib/types/schemas/recruitment-schema.ts';

interface UseChoiceMapParams {
recruitment: z.infer<typeof RecruitmentSchema> | undefined;
}
// interface UseChoiceMapParams {
// recruitment: z.infer<typeof RecruitmentSchema> | undefined;
// }

export type ChoiceMap = { [questionId: number]: number[] };

export const useChoiceMap = ({ recruitment }: UseChoiceMapParams) => {
const [choiceMap, setChoiceMap] = useState<ChoiceMap>({});
const [isChoiceMapReady, setIsChoiceMapReady] = useState(false);

useEffect(() => {
if (recruitment?.sections) {
const map: ChoiceMap = {};
/*
FixMe
- 필요없다고 완전히 판단되면 제거 및 util 로 옮기기
*/

recruitment.sections.forEach((section) => {
section.questions.forEach((question) => {
if (question.type === 'SELECTIVE' && question.choices.length > 0) {
map[question.id] = question.choices.map((choice) => choice.id);
}
});
});

setChoiceMap(map);
setIsChoiceMapReady(Object.keys(map).length > 0);
}
}, [recruitment]);
export type ChoiceMap = { [questionId: number]: number[] };

return {
choiceMap,
isChoiceMapReady,
};
};
// export const useChoiceMap = ({ recruitment }: UseChoiceMapParams) => {
// const [choiceMap, setChoiceMap] = useState<ChoiceMap>({});
// const [isChoiceMapReady, setIsChoiceMapReady] = useState(false);
//
// useEffect(() => {
// if (recruitment?.sections) {
// const map: ChoiceMap = {};
//
// recruitment.sections.forEach((section) => {
// section.questions.forEach((question) => {
// if (question.type === 'SELECTIVE' && question.choices.length > 0) {
// map[question.id] = question.choices.map((choice) => choice.id);
// }
// });
// });
//
// setChoiceMap(map);
// setIsChoiceMapReady(Object.keys(map).length > 0);
// }
// }, [recruitment]);
//
// return {
// choiceMap,
// isChoiceMapReady,
// };
// };

export const generateChoiceMap = (
recruitment: z.infer<typeof RecruitmentSchema>,
Expand Down
113 changes: 55 additions & 58 deletions src/app/apply/[recruitmentCode]/_hooks/use-section-selection.tsx
Original file line number Diff line number Diff line change
@@ -1,58 +1,55 @@
import { UseFormClearErrors } from 'react-hook-form';
import { useEffect, useState } from 'react';
import { getInitialSectionSelection } from '../_utils/utils';
import { SHARED_SECTION_INDEX } from '../page';
import { z } from 'zod';
import { RecruitmentSchema } from '../../../../lib/types/schemas/recruitment-schema.ts';
import { ApplicationDetailSchema } from '../../../../lib/types/schemas/application-schema.ts';

type UseSectionSelectionParams = {
recruitment?: z.infer<typeof RecruitmentSchema>;
application?: z.infer<typeof ApplicationDetailSchema>;

// eslint-disable-next-line @typescript-eslint/no-explicit-any
clearErrors: UseFormClearErrors<any>;
};

export const useSectionSelection = ({
recruitment,
application,
clearErrors,
}: UseSectionSelectionParams) => {
// 공통 섹션
const sharedSection = recruitment?.sections[SHARED_SECTION_INDEX];

// 초기 focus 섹션 index
const initialSectionSelections = getInitialSectionSelection(
application?.sections,
recruitment?.sections,
);

// 선택된 섹션 index
const [selectedSectionIndex, setSelectedSectionIndex] = useState<number>(
initialSectionSelections,
);

// 선택된 섹션
const selectedSection = recruitment?.sections[selectedSectionIndex];
const isOnlySharedSection = recruitment?.sections.length === 1;

useEffect(() => {
setSelectedSectionIndex(initialSectionSelections);
}, [initialSectionSelections]);

const handleSectionSelectionChange = (index: number) => {
setSelectedSectionIndex(index);

// 선택된 섹션 변경 시, 에러 메시지 초기화
clearErrors(`sections.${selectedSectionIndex}.answers`);
};

return {
sharedSection,
selectedSectionIndex,
selectedSection,
isOnlySharedSection,
handleSectionSelectionChange,
};
};
/*
FixMe
- 필요없다고 완전히 판단되면 제거
*/

// type UseSectionSelectionParams = {
// recruitment?: z.infer<typeof RecruitmentSchema>;
// application?: z.infer<typeof ApplicationDetailSchema>;
//
// // eslint-disable-next-line @typescript-eslint/no-explicit-any
// clearErrors: UseFormClearErrors<any>;
// };

// export const useSectionSelection = ({
// recruitment,
// application,
// clearErrors,
// }: UseSectionSelectionParams) => {
// // 공통 섹션
// const sharedSection = recruitment?.sections[SHARED_SECTION_INDEX];
//
// // 초기 focus 섹션 index
// const initialSectionSelections = getInitialSectionSelection(
// application?.sections,
// recruitment?.sections,
// );
//
// // 선택된 섹션 index
// const [selectedSectionIndex, setSelectedSectionIndex] = useState<number>(
// initialSectionSelections,
// );
//
// // 선택된 섹션
// const selectedSection = recruitment?.sections[selectedSectionIndex];
// const isOnlySharedSection = recruitment?.sections.length === 1;
//
// useEffect(() => {
// setSelectedSectionIndex(initialSectionSelections);
// }, [initialSectionSelections]);
//
// const handleSectionSelectionChange = (index: number) => {
// setSelectedSectionIndex(index);
//
// // 선택된 섹션 변경 시, 에러 메시지 초기화
// clearErrors(`sections.${selectedSectionIndex}.answers`);
// };
//
// return {
// sharedSection,
// selectedSectionIndex,
// selectedSection,
// isOnlySharedSection,
// handleSectionSelectionChange,
// };
// };
18 changes: 17 additions & 1 deletion src/app/recruit/_components/recruit-complete/footer-section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import useAdminApi from '../../../../apis/admin-api.ts';
import CrewsFooter from '../../../../components/molecule/crews-footer.tsx';
import { z } from 'zod';
import { ProgressSchema } from '../../../../lib/types/schemas/progress-schema.ts';
import {
Tooltip,
TooltipContent,
TooltipTrigger,
} from '../../../../components/shadcn/tooltip.tsx';

const url = import.meta.env.VITE_KAKAO_OPEN_CHAT;

Expand Down Expand Up @@ -79,7 +84,18 @@ const FooterSection = ({
<Loading />
) : null}
<CrewsFooter>
<Button size="lg">CSV 추출</Button>
<Tooltip>
<TooltipTrigger>
<Button size="lg" disabled>
CSV 추출
</Button>
</TooltipTrigger>

<TooltipContent>
<p>서비스 준비중 🙇🏻</p>
</TooltipContent>
</Tooltip>

<Button
size="lg"
disabled={progress === 'ANNOUNCED'}
Expand Down
13 changes: 8 additions & 5 deletions src/app/sign-in/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ import AdminSignIn from './_components/admin-sign-in.tsx';
import ApplicantSignIn from './_components/applicant-sign-in.tsx';
import { useState } from 'react';
import { Link, useLocation } from 'react-router-dom';
import { Tooltip, TooltipContent, TooltipTrigger } from '../../components/shadcn/tooltip.tsx';
import {
Tooltip,
TooltipContent,
TooltipTrigger,
} from '../../components/shadcn/tooltip.tsx';
import { z } from 'zod';
import { RoleSchema } from '../../lib/types/schemas/role-schema.ts';

const Page = () => {
const location = useLocation();
const [loginType, setLoginType] = useState<z.infer<typeof RoleSchema>>(
location.state?.loginType ?? 'APPLICANT'
location.state?.loginType ?? 'APPLICANT',
);

const toggleLoginType = () => {
Expand All @@ -20,8 +24,7 @@ const Page = () => {

return (
<Container className="flex items-center justify-center">
<section
className="w-full max-w-[650px] rounded-md border border-crews-g01 px-32 py-40 shadow-custom-light-shadow">
<section className="w-full max-w-[650px] rounded-md border border-crews-g01 px-32 py-40 shadow-custom-light-shadow">
<div className="mb-6 flex flex-col items-center text-3xl tracking-widest">
<p className="font-bold">
{loginType === 'APPLICANT' ? '지원자' : '모집자'}
Expand Down Expand Up @@ -61,7 +64,7 @@ const Page = () => {
<p className="hover:underline">비밀번호 찾기</p>
</TooltipTrigger>
<TooltipContent side="bottom">
<p>개발중입니다 😅</p>
<p className="font-normal text-crews-bk01">서비스 준비중 🙇🏻</p>
</TooltipContent>
</Tooltip>
</div>
Expand Down
4 changes: 1 addition & 3 deletions src/components/molecule/crews-header.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import AnchorIcon from '../../assets/icons/anchor-icon.svg?react';
import CircleUserIcon from '../../assets/icons/circle-user-icon.svg?react';
import { Link, useLocation, useNavigate } from 'react-router-dom';
import { Link, useLocation } from 'react-router-dom';
import useSession from '../../hooks/use-session.ts';
import { cn } from '../../lib/utils/utils.ts';
import { useMutation } from '@tanstack/react-query';
Expand All @@ -17,12 +17,10 @@ const CrewsHeader = () => {
const signOutMutation = useMutation({ mutationFn: signOut });

const { toast } = useToast();
const navigate = useNavigate();

const handleSignOutClick = async () => {
try {
await signOutMutation.mutateAsync();
navigate('/', { state: { logout: true } });

toast({
title: `안녕히가세요 👋`,
Expand Down
2 changes: 1 addition & 1 deletion src/components/recruitment-view/question-boxes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ const NarrativeBox = ({
<textarea
rows={3}
className="w-full rounded-lg p-2 text-xs outline outline-1 outline-crews-g02 placeholder:font-light placeholder:text-crews-g03"
disabled={true}
readOnly
placeholder="이곳에 답변을 입력해주세요."
value={answer?.content ?? ''}
/>
Expand Down
17 changes: 2 additions & 15 deletions src/components/wrapper/auth-redirect-wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Navigate, Outlet, useLocation } from 'react-router-dom';
import useSession from '../../hooks/use-session';
import { z } from 'zod';
import { RoleSchema } from '../../lib/types/schemas/role-schema.ts';
import { useToast } from '../../hooks/use-toast.ts';

const AuthRedirectWrapper = ({
availableRoles,
Expand All @@ -12,16 +11,8 @@ const AuthRedirectWrapper = ({
const { accessToken, role } = useSession();
const location = useLocation();

const { toast } = useToast();
if (!accessToken) {
{
!location.state?.logout &&
toast({
title: '로그인이 필요한 페이지입니다.',
state: 'warning',
});
}

!location.state?.logout && alert('로그인이 필요한 페이지입니다.');
return (
<Navigate
to="/sign-in"
Expand All @@ -32,11 +23,7 @@ const AuthRedirectWrapper = ({
);
}
if (!availableRoles.includes(role)) {
toast({
title: '허용되지 않은 페이지입니다.',
state: 'warning',
});

alert('허용되지 않은 페이지입니다.');
return <Navigate to="/" />;
}
return <Outlet />;
Expand Down
2 changes: 1 addition & 1 deletion src/components/wrapper/try-login-wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { printCustomError } from '../../lib/utils/error.ts';
import { Outlet } from 'react-router-dom';

/*
@ToDo
ToDo
- 나중에 accessToken 시간 확 줄여서 테스트
*/

Expand Down
30 changes: 19 additions & 11 deletions src/lib/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,23 @@ export function extractRole(token: string) {
export function findSelectedSection(
answersBySection: z.infer<typeof AnswersBySectionSchema>[],
): number[] {
return answersBySection.reduce((acc: number[], ansBySec) => {
if (
ansBySec.answers.some((ans) => {
if (ans.type === 'NARRATIVE' && ans.content !== null) return true;
if (ans.type === 'SELECTIVE' && ans.choiceIds !== null) return true;
return false;
})
)
acc.push(ansBySec.sectionId);
return acc;
}, []);
const selectedSections = answersBySection.reduce(
(acc: number[], ansBySec) => {
if (
ansBySec.answers.some((ans) => {
if (ans.type === 'NARRATIVE' && ans.content !== null) return true;
if (ans.type === 'SELECTIVE' && ans.choiceIds !== null) return true;
return false;
})
)
acc.push(ansBySec.sectionId);
return acc;
},
[],
);

if (answersBySection.length > 1 && selectedSections.length === 1)
selectedSections.push(1);

return selectedSections;
}

0 comments on commit b7efd4a

Please sign in to comment.