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

๐Ÿ”€ ๊ฐ„๋‹จํ•œ ๋ณ€๊ฒฝ์‚ฌํ•ญ ์ ์šฉ #57

Merged
merged 3 commits into from
Dec 16, 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
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
Loading