Skip to content
Merged
14 changes: 12 additions & 2 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import LoginTab from '@/pages/AdminPage/auth/LoginTab/LoginTab';
import PrivateRoute from '@/pages/AdminPage/auth/PrivateRoute/PrivateRoute';
import PhotoEditTab from '@/pages/AdminPage/tabs/PhotoEditTab/PhotoEditTab';
import ApplicationForm from '@/pages/AdminPage/application/ApplicationForm';
import AnswerApplicationForm from '@/pages/AdminPage/application/answer/AnswerApplicationForm';

Check warning on line 17 in frontend/src/App.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/src/App.tsx#L17

Added line #L17 was not covered by tests
import CreateApplicationForm from '@/pages/AdminPage/application/CreateApplicationForm';

const queryClient = new QueryClient();
Expand Down Expand Up @@ -75,7 +75,17 @@
</AdminClubProvider>
}
/>
<Route path='view-application' element={<ApplicationForm />} />
{/*//todo /:clubid로 수정 필요*/}
{/*<Route*/}
{/* path='/application/:clubid'*/}
{/* element={<AnswerApplicationForm />}*/}
{/*/>*/}
<Route path='/application' element={<AnswerApplicationForm />} />
{/*TODO: CreateForm은 관리자 기능이므로 추후 /admin/* 경로 안으로 이동 필요*/}
<Route
path='create-application'
element={<CreateApplicationForm />}
/>
<Route path='*' element={<Navigate to='/' replace />} />
</Routes>
</BrowserRouter>
Expand Down
33 changes: 33 additions & 0 deletions frontend/src/hooks/useAnswers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { useState } from 'react';

Check warning on line 1 in frontend/src/hooks/useAnswers.ts

View check run for this annotation

Codecov / codecov/patch

frontend/src/hooks/useAnswers.ts#L1

Added line #L1 was not covered by tests
import { AnswerItem } from '@/types/application';

export const useAnswers = () => {
const [answers, setAnswers] = useState<AnswerItem[]>([]);

Check warning on line 5 in frontend/src/hooks/useAnswers.ts

View check run for this annotation

Codecov / codecov/patch

frontend/src/hooks/useAnswers.ts#L4-L5

Added lines #L4 - L5 were not covered by tests

const updateSingleAnswer = (id: number, value: string) => {
setAnswers((prev) => [
...prev.filter((a) => a.id !== id),

Check warning on line 9 in frontend/src/hooks/useAnswers.ts

View check run for this annotation

Codecov / codecov/patch

frontend/src/hooks/useAnswers.ts#L7-L9

Added lines #L7 - L9 were not covered by tests
{ id, answer: value },
]);
};

const updateMultiAnswer = (id: number, values: string[]) => {
setAnswers((prev) => [
...prev.filter((a) => a.id !== id),
...values.map((v) => ({ id, answer: v })),

Check warning on line 17 in frontend/src/hooks/useAnswers.ts

View check run for this annotation

Codecov / codecov/patch

frontend/src/hooks/useAnswers.ts#L14-L17

Added lines #L14 - L17 were not covered by tests
]);
};

const onAnswerChange = (id: number, value: string | string[]) => {

Check warning on line 21 in frontend/src/hooks/useAnswers.ts

View check run for this annotation

Codecov / codecov/patch

frontend/src/hooks/useAnswers.ts#L21

Added line #L21 was not covered by tests
if (Array.isArray(value)) {
updateMultiAnswer(id, value);

Check warning on line 23 in frontend/src/hooks/useAnswers.ts

View check run for this annotation

Codecov / codecov/patch

frontend/src/hooks/useAnswers.ts#L23

Added line #L23 was not covered by tests
} else {
updateSingleAnswer(id, value);

Check warning on line 25 in frontend/src/hooks/useAnswers.ts

View check run for this annotation

Codecov / codecov/patch

frontend/src/hooks/useAnswers.ts#L25

Added line #L25 was not covered by tests
}
};

const getAnswersById = (id: number) =>
answers.filter((a) => a.id === id).map((a) => a.answer);

Check warning on line 30 in frontend/src/hooks/useAnswers.ts

View check run for this annotation

Codecov / codecov/patch

frontend/src/hooks/useAnswers.ts#L29-L30

Added lines #L29 - L30 were not covered by tests

return { onAnswerChange, getAnswersById };

Check warning on line 32 in frontend/src/hooks/useAnswers.ts

View check run for this annotation

Codecov / codecov/patch

frontend/src/hooks/useAnswers.ts#L32

Added line #L32 was not covered by tests
};
71 changes: 0 additions & 71 deletions frontend/src/pages/AdminPage/application/ApplicationForm.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import styled from 'styled-components';

Check warning on line 1 in frontend/src/pages/AdminPage/application/answer/AnswerApplicationForm.styles.ts

View check run for this annotation

Codecov / codecov/patch

frontend/src/pages/AdminPage/application/answer/AnswerApplicationForm.styles.ts#L1

Added line #L1 was not covered by tests

export const FormTitle = styled.h1`

Check warning on line 3 in frontend/src/pages/AdminPage/application/answer/AnswerApplicationForm.styles.ts

View check run for this annotation

Codecov / codecov/patch

frontend/src/pages/AdminPage/application/answer/AnswerApplicationForm.styles.ts#L3

Added line #L3 was not covered by tests
font-size: 2.5rem;
font-weight: 700;
border: none;
outline: none;
margin-top: 20px;
margin-bottom: 46px;
`;

export const ButtonWrapper = styled.div`

Check warning on line 12 in frontend/src/pages/AdminPage/application/answer/AnswerApplicationForm.styles.ts

View check run for this annotation

Codecov / codecov/patch

frontend/src/pages/AdminPage/application/answer/AnswerApplicationForm.styles.ts#L12

Added line #L12 was not covered by tests
display: flex;
justify-content: flex-end;
`;

export const submitButton = styled.button`

Check warning on line 17 in frontend/src/pages/AdminPage/application/answer/AnswerApplicationForm.styles.ts

View check run for this annotation

Codecov / codecov/patch

frontend/src/pages/AdminPage/application/answer/AnswerApplicationForm.styles.ts#L17

Added line #L17 was not covered by tests
padding: 10px 56px;
background-color: #ff5414;
border-radius: 10px;
border: none;
color: #fff;
font-size: 1.25rem;
font-weight: 600;
letter-spacing: -0.4px;
transition: background-color 0.2s;
margin: 50px 0;

&:hover {
background-color: #ffad8e;
animation: pulse 0.4s ease-in-out;
}

&:active {
transform: scale(0.95);
}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { mockData } from '@/mocks/data/mockData';
import { PageContainer } from '@/styles/PageContainer.styles';
import * as Styled from './AnswerApplicationForm.styles';
import Header from '@/components/common/Header/Header';

Check warning on line 4 in frontend/src/pages/AdminPage/application/answer/AnswerApplicationForm.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/src/pages/AdminPage/application/answer/AnswerApplicationForm.tsx#L1-L4

Added lines #L1 - L4 were not covered by tests
import { useParams } from 'react-router-dom';
import { useGetClubDetail } from '@/hooks/queries/club/useGetClubDetail';
import ClubProfile from '@/pages/ClubDetailPage/components/ClubProfile/ClubProfile';
import { useAnswers } from '@/hooks/useAnswers';
import QuestionAnswerer from '@/pages/AdminPage/application/components/QuestionAnswerer/QuestionAnswerer';

Check warning on line 9 in frontend/src/pages/AdminPage/application/answer/AnswerApplicationForm.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/src/pages/AdminPage/application/answer/AnswerApplicationForm.tsx#L6-L9

Added lines #L6 - L9 were not covered by tests

const AnswerApplicationForm = () => {

Check warning on line 11 in frontend/src/pages/AdminPage/application/answer/AnswerApplicationForm.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/src/pages/AdminPage/application/answer/AnswerApplicationForm.tsx#L11

Added line #L11 was not covered by tests
//const { clubId } = useParams<{ clubId: string }>();
const clubId = '67e54ae51cfd27718dd40bec'; // 하드코딩된 club ID

Check warning on line 13 in frontend/src/pages/AdminPage/application/answer/AnswerApplicationForm.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/src/pages/AdminPage/application/answer/AnswerApplicationForm.tsx#L13

Added line #L13 was not covered by tests
const { data: clubDetail, error } = useGetClubDetail(clubId || '');
const { onAnswerChange, getAnswersById } = useAnswers();

Check warning on line 15 in frontend/src/pages/AdminPage/application/answer/AnswerApplicationForm.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/src/pages/AdminPage/application/answer/AnswerApplicationForm.tsx#L15

Added line #L15 was not covered by tests
if (!clubDetail) {
return null;

Check warning on line 17 in frontend/src/pages/AdminPage/application/answer/AnswerApplicationForm.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/src/pages/AdminPage/application/answer/AnswerApplicationForm.tsx#L17

Added line #L17 was not covered by tests
}

if (error) {
return <div>에러가 발생했습니다.</div>;

Check warning on line 21 in frontend/src/pages/AdminPage/application/answer/AnswerApplicationForm.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/src/pages/AdminPage/application/answer/AnswerApplicationForm.tsx#L21

Added line #L21 was not covered by tests
}

return (

Check warning on line 24 in frontend/src/pages/AdminPage/application/answer/AnswerApplicationForm.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/src/pages/AdminPage/application/answer/AnswerApplicationForm.tsx#L24

Added line #L24 was not covered by tests
<>
<Header />
<PageContainer style={{ paddingTop: '172px' }}>
<ClubProfile
name={clubDetail.name}
logo={clubDetail.logo}
division={clubDetail.division}
category={clubDetail.category}
tags={clubDetail.tags}
/>
<Styled.FormTitle>{mockData.form_title}</Styled.FormTitle>
{mockData.questions.map((q) => (
<QuestionAnswerer

Check warning on line 37 in frontend/src/pages/AdminPage/application/answer/AnswerApplicationForm.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/src/pages/AdminPage/application/answer/AnswerApplicationForm.tsx#L37

Added line #L37 was not covered by tests
key={q.id}
question={q}
selectedAnswers={getAnswersById(q.id)}
onChange={onAnswerChange}
/>
))}
<Styled.ButtonWrapper>
<Styled.submitButton>제출하기</Styled.submitButton>
</Styled.ButtonWrapper>
</PageContainer>
</>
);
};

export default AnswerApplicationForm;

Check warning on line 52 in frontend/src/pages/AdminPage/application/answer/AnswerApplicationForm.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/src/pages/AdminPage/application/answer/AnswerApplicationForm.tsx#L52

Added line #L52 was not covered by tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { Question } from '@/types/application';
import ShortText from '@/pages/AdminPage/application/fields/ShortText';
import LongText from '@/pages/AdminPage/application/fields/LongText';

Check warning on line 3 in frontend/src/pages/AdminPage/application/components/QuestionAnswerer/QuestionAnswerer.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/src/pages/AdminPage/application/components/QuestionAnswerer/QuestionAnswerer.tsx#L2-L3

Added lines #L2 - L3 were not covered by tests
import Choice from '@/pages/AdminPage/application/fields/Choice';

interface QuestionAnswererProps {
question: Question;
selectedAnswers: string[];
onChange: (id: number, value: string | string[]) => void;
}

const QuestionAnswerer = ({

Check warning on line 12 in frontend/src/pages/AdminPage/application/components/QuestionAnswerer/QuestionAnswerer.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/src/pages/AdminPage/application/components/QuestionAnswerer/QuestionAnswerer.tsx#L12

Added line #L12 was not covered by tests
question,
selectedAnswers,
onChange,
}: QuestionAnswererProps) => {
const baseProps = {

Check warning on line 17 in frontend/src/pages/AdminPage/application/components/QuestionAnswerer/QuestionAnswerer.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/src/pages/AdminPage/application/components/QuestionAnswerer/QuestionAnswerer.tsx#L17

Added line #L17 was not covered by tests
id: question.id,
title: question.title,
description: question.description,
required: question.options.required,
mode: 'answer' as const,
};

switch (question.type) {
case 'NAME':
case 'EMAIL':
case 'PHONE_NUMBER':
case 'SHORT_TEXT':
return (

Check warning on line 30 in frontend/src/pages/AdminPage/application/components/QuestionAnswerer/QuestionAnswerer.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/src/pages/AdminPage/application/components/QuestionAnswerer/QuestionAnswerer.tsx#L30

Added line #L30 was not covered by tests
<ShortText
{...baseProps}
answer={selectedAnswers[0] ?? ''}
onAnswerChange={(value) => onChange(question.id, value)}

Check warning on line 34 in frontend/src/pages/AdminPage/application/components/QuestionAnswerer/QuestionAnswerer.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/src/pages/AdminPage/application/components/QuestionAnswerer/QuestionAnswerer.tsx#L34

Added line #L34 was not covered by tests
/>
);

case 'LONG_TEXT':
return (

Check warning on line 39 in frontend/src/pages/AdminPage/application/components/QuestionAnswerer/QuestionAnswerer.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/src/pages/AdminPage/application/components/QuestionAnswerer/QuestionAnswerer.tsx#L39

Added line #L39 was not covered by tests
<LongText
{...baseProps}
answer={selectedAnswers[0] ?? ''}
onAnswerChange={(value) => onChange(question.id, value)}

Check warning on line 43 in frontend/src/pages/AdminPage/application/components/QuestionAnswerer/QuestionAnswerer.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/src/pages/AdminPage/application/components/QuestionAnswerer/QuestionAnswerer.tsx#L43

Added line #L43 was not covered by tests
/>
);

case 'CHOICE':
case 'MULTI_CHOICE':
return (

Check warning on line 49 in frontend/src/pages/AdminPage/application/components/QuestionAnswerer/QuestionAnswerer.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/src/pages/AdminPage/application/components/QuestionAnswerer/QuestionAnswerer.tsx#L49

Added line #L49 was not covered by tests
<></>
// <Choice
// {...baseProps}
// items={question.items}
// isMulti={question.type === 'MULTI_CHOICE'}
// answer={selectedAnswers}
// onAnswerChange={(value) => onChange(question.id, value)}
// />
);

default:
return <div>지원하지 않는 질문 유형입니다: {question.type}</div>;

Check warning on line 61 in frontend/src/pages/AdminPage/application/components/QuestionAnswerer/QuestionAnswerer.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/src/pages/AdminPage/application/components/QuestionAnswerer/QuestionAnswerer.tsx#L61

Added line #L61 was not covered by tests
}
};

export default QuestionAnswerer;

Check warning on line 65 in frontend/src/pages/AdminPage/application/components/QuestionAnswerer/QuestionAnswerer.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/src/pages/AdminPage/application/components/QuestionAnswerer/QuestionAnswerer.tsx#L65

Added line #L65 was not covered by tests
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const QuestionTitleText = styled.input`
font-size: 1.25rem;
font-weight: 700;
line-height: normal;
width: 100%;
field-sizing: content;

&::placeholder {
color: #c5c5c5;
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/types/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,8 @@ export interface ApplicationFormData {
form_title: string;
questions: Question[];
}

export interface AnswerItem {
id: number;
answer: string;
}