Skip to content

Commit

Permalink
Merge pull request #57 from School-of-Company/fix/form-component-mount
Browse files Browse the repository at this point in the history
🔀 간단한 변경사항 적용
  • Loading branch information
Ethen1264 authored Dec 16, 2024
2 parents 658d21d + 72dcde3 commit 1fb6826
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 22 deletions.
16 changes: 12 additions & 4 deletions src/shared/ui/SelectUserType/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';

import { useState } from 'react';
import React, { useState, useEffect } from 'react';
import { ArrowDown } from '@/shared/assets/icons';

interface Option {
Expand All @@ -10,17 +10,25 @@ interface Option {

interface SelectProps {
options: Option[];
defaultValue?: string;
value: string;
onChange?: (value: string) => void;
}

const SelectUserType = ({ options, defaultValue, onChange }: SelectProps) => {
const SelectUserType = ({ options, value, onChange }: SelectProps) => {
const [isOpen, setIsOpen] = useState(false);
const [selectedOption, setSelectedOption] = useState<Option | undefined>(
options.find((option) => option.value === defaultValue) || options[0],
options.find((option) => option.value === value) || options[0],
);

useEffect(() => {
const newSelectedOption = options.find((option) => option.value === value);
if (newSelectedOption) {
setSelectedOption(newSelectedOption);
}
}, [value, options]);

const toggleOpen = () => setIsOpen((prev) => !prev);

const handleOptionClick = (option: Option) => {
setSelectedOption(option);
setIsOpen(false);
Expand Down
10 changes: 2 additions & 8 deletions src/widgets/expo-manage/ui/ExpoManageForm/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';

import React, { useEffect, useState, useMemo } from 'react';
import React, { useState, useMemo } from 'react';
import withLoading from '@/shared/hocs/withLoading';
import { fileActions } from '@/shared/model/footerActions';
import { Participant, Trainee } from '@/shared/types/expo-manage/type';
Expand All @@ -11,18 +11,13 @@ import { useExpoManageQueries } from '../../model/useExpoData';

const ExpoManageForm = ({ id }: { id: string }) => {
const [selectOption, setSelectOption] = useState<string>('trainee');
const [resetKey, setResetKey] = useState(0);

const { expoQueries, isLoading } = useExpoManageQueries(id, selectOption);

const requestPrintCategories = useMemo(() => {
return category(selectOption);
}, [selectOption]);

useEffect(() => {
setResetKey((prevKey) => prevKey + 1);
}, [selectOption]);

const expoData = expoQueries.data || [];

return withLoading({
Expand All @@ -31,11 +26,10 @@ const ExpoManageForm = ({ id }: { id: string }) => {
<div className="mx-auto w-full max-w-[1200px] space-y-[30px] px-5">
<SelectUserType
options={selectOptionCategories}
defaultValue="trainee"
value={selectOption}
onChange={(value) => setSelectOption(value)}
/>
<TableForm<Trainee | Participant>
key={resetKey}
categories={requestPrintCategories}
data={expoData}
maxHeight="414px"
Expand Down
8 changes: 8 additions & 0 deletions src/widgets/program/model/category.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const standardCategories = ['번호', '프로그램', '시작시간', '종료시간'];
export const trainingCategories = [
'번호',
'프로그램',
'시작시간',
'종료시간',
'상태',
];
14 changes: 4 additions & 10 deletions src/widgets/program/ui/ProgramForm/index.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
'use client';

import { useRouter, useSearchParams } from 'next/navigation';
import React, { useEffect, useState, useMemo } from 'react';
import React, { useMemo } from 'react';
import { ProgramNavigation } from '@/entities/program';
import withLoading from '@/shared/hocs/withLoading';
import { routeActions } from '@/shared/model/footerActions';
import { TableForm } from '@/shared/ui/Table';
import { standardCategories, trainingCategories } from '../../model/category';
import { useProgramQueries } from '../../model/useProgramData';

const ProgramForm = ({ id }: { id: string }) => {
const searchParams = useSearchParams();
const navigation = searchParams.get('navigation') || 'standard';
const [resetKey, setResetKey] = useState(0);

const router = useRouter();

const { programQueries, isLoading } = useProgramQueries(id, navigation);

const requestPrintCategories = useMemo(() => {
return navigation === 'training'
? ['번호', '프로그램', '시작시간', '종료시간', '상태']
: ['번호', '프로그램', '시작시간', '종료시간'];
}, [navigation]);

useEffect(() => {
setResetKey((prevKey) => prevKey + 1);
return navigation === 'training' ? trainingCategories : standardCategories;
}, [navigation]);

const programData = programQueries.data || [];
Expand All @@ -34,7 +29,6 @@ const ProgramForm = ({ id }: { id: string }) => {
<div className="mx-auto w-full max-w-[1200px] space-y-[46px] px-5">
<ProgramNavigation />
<TableForm
key={resetKey}
categories={requestPrintCategories}
data={programData}
maxHeight="414px"
Expand Down

0 comments on commit 1fb6826

Please sign in to comment.