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

Feature/#302 커리큘럼 관련 api 수정 #316

Merged
merged 3 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/app/api/study.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fetcher } from '@/app/api/fetcher';
import { Study, Curriculum } from '@/types';
import { Study, Curriculum, PostCurriculum } from '@/types';

const studyFetcher = fetcher();

Expand Down Expand Up @@ -98,7 +98,7 @@ const getCurriculum = (token: string, studyId: number) =>
const postCurriculum = (
token: string,
studyId: number,
curriculumItems: Curriculum[],
curriculumItems: PostCurriculum[],
deletedCurriculumItems: Curriculum[],
) =>
studyFetcher(`/studies/${studyId}/curriculums`, {
Expand Down
1 change: 1 addition & 0 deletions src/app/team/[teamId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ const Page = ({ params }: { params: { teamId: number } }) => {

const myTeam = useAtomValue(myTeamAtom);
const [isMyTeam, setIsMyTeam] = useState<boolean>(false);

useEffect(() => {
if (myTeam.teams !== undefined) {
const res = myTeam.teams.filter((teamId) => teamId === params.teamId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const CurriculumItem = ({ id, name, itemOrder, isChecked: isCheckedProps, partic
};

return (
<Flex key={id.toString()} align="center" gap="4" px="4">
<Flex key={id?.toString()} align="center" gap="4" px="4">
<Text textStyle="bold_xl" color={isChecked ? 'orange' : 'orange_light'}>
{itemOrder.toString().padStart(2, '0')}
</Text>
Expand Down
101 changes: 53 additions & 48 deletions src/containers/study/CurriculumModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const CurriculumModal = ({ isOpen, onClose, originCurriculums }: CurriculumModal

const [newCurriculum, setNewCurriculum] = useState<string>('');
const [newCurriculumId, setNewCurriculumId] = useState<number>(1);
const [firstNewCurriculumId, setFirstNewCurriculumId] = useState<number>(0);

const editCurriculumRef = React.useRef<HTMLTextAreaElement>();

Expand Down Expand Up @@ -91,7 +92,7 @@ const CurriculumModal = ({ isOpen, onClose, originCurriculums }: CurriculumModal
}));

const curriculumItems = curriculums.map((curriculum) => ({
id: curriculum.id,
id: curriculum.id !== null && curriculum.id > firstNewCurriculumId ? null : curriculum.id,
name: curriculum.name,
itemOrder: curriculum.itemOrder,
}));
Expand Down Expand Up @@ -134,6 +135,7 @@ const CurriculumModal = ({ isOpen, onClose, originCurriculums }: CurriculumModal
);

setNewCurriculumId((originCurriculums?.at(-1)?.id ?? 0) + 1);
setFirstNewCurriculumId(originCurriculums?.at(-1)?.id ?? 0);
}, [originCurriculums]);

return (
Expand All @@ -152,53 +154,56 @@ const CurriculumModal = ({ isOpen, onClose, originCurriculums }: CurriculumModal
<Droppable droppableId="DropLand">
{(provided) => (
<Flex direction="column" gap="4" m="4" {...provided.droppableProps} ref={provided.innerRef}>
{curriculums.map((curriculum, index) => (
<Draggable key={curriculum.id} draggableId={curriculum.id.toString()} index={index}>
{(innerProvided) => (
<Flex
ref={innerProvided.innerRef}
align="center"
gap="2"
{...innerProvided.draggableProps}
{...innerProvided.dragHandleProps}
>
<Text textStyle="bold_xl" color={curriculum.isEdit ? 'orange' : 'orange_light'}>
{curriculum.itemOrder.toString().padStart(2, '0')}
</Text>

<AutoResizeTextarea
ref={editCurriculumRef.current}
bg={curriculum.isEdit ? 'orange' : 'orange_light'}
zIndex={!curriculum.isEdit ? '-1' : '1'}
value={curriculum.name}
onChange={handleCurriculumChange(index)}
RightIconButton={
<>
<IconButton
aria-label="edit curriculum"
icon={<BiEdit />}
onClick={() => {
handleEditButtonClick(index);
}}
size="icon_md"
variant="transparent"
/>
<IconButton
aria-label="delete curriculum"
icon={<BiTrash />}
onClick={() => {
handleDeleteButtonClick(index);
}}
size="icon_md"
variant="transparent"
/>
</>
}
/>
</Flex>
)}
</Draggable>
))}
{curriculums.map(
(curriculum, index) =>
curriculum.id && (
<Draggable key={curriculum.id} draggableId={curriculum.id.toString()} index={index}>
{(innerProvided) => (
<Flex
ref={innerProvided.innerRef}
align="center"
gap="2"
{...innerProvided.draggableProps}
{...innerProvided.dragHandleProps}
>
<Text textStyle="bold_xl" color={curriculum.isEdit ? 'orange' : 'orange_light'}>
{curriculum.itemOrder.toString().padStart(2, '0')}
</Text>

<AutoResizeTextarea
ref={editCurriculumRef.current}
bg={curriculum.isEdit ? 'orange' : 'orange_light'}
zIndex={!curriculum.isEdit ? '-1' : '1'}
value={curriculum.name}
onChange={handleCurriculumChange(index)}
RightIconButton={
<>
<IconButton
aria-label="edit curriculum"
icon={<BiEdit />}
onClick={() => {
handleEditButtonClick(index);
}}
size="icon_md"
variant="transparent"
/>
<IconButton
aria-label="delete curriculum"
icon={<BiTrash />}
onClick={() => {
handleDeleteButtonClick(index);
}}
size="icon_md"
variant="transparent"
/>
</>
}
/>
</Flex>
)}
</Draggable>
),
)}
{provided.placeholder}
</Flex>
)}
Expand Down
10 changes: 9 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,15 @@ export interface TeamMemberDetail extends Member {
}

export interface Curriculum {
id: number;
id: number | null;
participantId?: number;
name: string;
itemOrder: number;
isChecked?: boolean;
}

export interface PostCurriculum {
id: null;
participantId?: number;
name: string;
itemOrder: number;
Expand Down