Skip to content

Commit

Permalink
๐Ÿ› ์—ฐ๊ตฌ ๊ฒ€์ˆ˜ (#298)
Browse files Browse the repository at this point in the history
  • Loading branch information
Limchansol authored Jan 26, 2025
1 parent a54140f commit caa5f91
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 92 deletions.
12 changes: 3 additions & 9 deletions app/[locale]/research/centers/ResearchCenterDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ import HTMLViewer from '@/components/form/html/HTMLViewer';
import { researchCenters } from '@/constants/segmentNode';
import LinkIcon from '@/public/image/link_icon.svg';
import { WithLanguage } from '@/types/language';
import { errorToStr } from '@/utils/error';
import { getPath } from '@/utils/page';
import { handleServerAction } from '@/utils/serverActionError';
import { errorToast, successToast } from '@/utils/toast';
import { handleServerResponse } from '@/utils/serverActionError';

interface ResearchCenterDetailsProps {
center: ResearchCenter;
Expand All @@ -23,12 +21,8 @@ const centersPath = getPath(researchCenters);

export default function ResearchCenterDetails({ center, ids }: ResearchCenterDetailsProps) {
const handleDelete = async () => {
try {
handleServerAction(await deleteResearchCenterAction(ids));
successToast('์—ฐ๊ตฌ ์„ผํ„ฐ๋ฅผ ์‚ญ์ œํ–ˆ์Šต๋‹ˆ๋‹ค.');
} catch (e) {
errorToast(errorToStr(e));
}
const resp = await deleteResearchCenterAction(ids);
handleServerResponse(resp, { successMessage: '์—ฐ๊ตฌ ์„ผํ„ฐ๋ฅผ ์‚ญ์ œํ–ˆ์Šต๋‹ˆ๋‹ค.' });
};

return (
Expand Down
12 changes: 3 additions & 9 deletions app/[locale]/research/centers/create/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,16 @@

import { postResearchCenterAction } from '@/actions/research';
import PageLayout from '@/components/layout/pageLayout/PageLayout';
import { errorToStr } from '@/utils/error';
import { contentToFormData } from '@/utils/formData';
import { handleServerAction } from '@/utils/serverActionError';
import { errorToast, successToast } from '@/utils/toast';
import { handleServerResponse } from '@/utils/serverActionError';

import ResearchCenterEditor, { ResearchCenterFormData } from '../components/ResearchCenterEditor';

export default function ResearchCenterCreatePage() {
const onSubmit = async ({ image, ...requestObject }: ResearchCenterFormData) => {
const formData = contentToFormData('CREATE', { requestObject, image });
try {
handleServerAction(await postResearchCenterAction(formData));
successToast('์—ฐ๊ตฌ ์„ผํ„ฐ๋ฅผ ์ถ”๊ฐ€ํ–ˆ์Šต๋‹ˆ๋‹ค.');
} catch (e) {
errorToast(errorToStr(e));
}
const resp = await postResearchCenterAction(formData);
handleServerResponse(resp, { successMessage: '์—ฐ๊ตฌ ์„ผํ„ฐ๋ฅผ ์ถ”๊ฐ€ํ–ˆ์Šต๋‹ˆ๋‹ค.' });
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import { putResearchCenterAction } from '@/actions/research';
import { ResearchCenter } from '@/apis/types/research';
import PageLayout from '@/components/layout/pageLayout/PageLayout';
import { WithLanguage } from '@/types/language';
import { errorToStr } from '@/utils/error';
import { contentToFormData } from '@/utils/formData';
import { handleServerAction } from '@/utils/serverActionError';
import { errorToast, successToast } from '@/utils/toast';
import { handleServerResponse } from '@/utils/serverActionError';

import ResearchCenterEditor, { ResearchCenterFormData } from '../components/ResearchCenterEditor';

Expand All @@ -18,14 +16,8 @@ export default function ResearchCenterEditPageContent({
}) {
const onSubmit = async ({ image, ...requestObject }: ResearchCenterFormData) => {
const formData = contentToFormData('EDIT', { requestObject, image });
try {
handleServerAction(
await putResearchCenterAction({ ko: center.ko.id, en: center.en.id }, formData),
);
successToast('์—ฐ๊ตฌ ์„ผํ„ฐ๋ฅผ ์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค.');
} catch (e) {
errorToast(errorToStr(e));
}
const resp = await putResearchCenterAction({ ko: center.ko.id, en: center.en.id }, formData);
handleServerResponse(resp, { successMessage: '์—ฐ๊ตฌ ์„ผํ„ฐ๋ฅผ ์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค.' });
};

return (
Expand Down
12 changes: 3 additions & 9 deletions app/[locale]/research/groups/ResearchGroupDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ import LoginVisible from '@/components/common/LoginVisible';
import HTMLViewer from '@/components/form/html/HTMLViewer';
import { researchGroups } from '@/constants/segmentNode';
import { WithLanguage } from '@/types/language';
import { errorToStr } from '@/utils/error';
import { getPath } from '@/utils/page';
import { handleServerAction } from '@/utils/serverActionError';
import { errorToast, successToast } from '@/utils/toast';
import { handleServerResponse } from '@/utils/serverActionError';

import ResearchGroupLabs from './ResearchGroupLabs';

Expand All @@ -28,12 +26,8 @@ export default function ResearchGroupDetails({ group, ids }: ResearchGroupDetail
const t = useTranslations('Content');

const handleDelete = async () => {
try {
handleServerAction(await deleteResearchGroupAction(ids));
successToast('์—ฐ๊ตฌ ์ŠคํŠธ๋ฆผ์„ ์‚ญ์ œํ–ˆ์Šต๋‹ˆ๋‹ค.');
} catch (e) {
errorToast(errorToStr(e));
}
const resp = await deleteResearchGroupAction(ids);
handleServerResponse(resp, { successMessage: '์—ฐ๊ตฌ ์ŠคํŠธ๋ฆผ์„ ์‚ญ์ œํ–ˆ์Šต๋‹ˆ๋‹ค.' });
};

return (
Expand Down
12 changes: 3 additions & 9 deletions app/[locale]/research/groups/create/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,16 @@

import { postResearchGroupAction } from '@/actions/research';
import PageLayout from '@/components/layout/pageLayout/PageLayout';
import { errorToStr } from '@/utils/error';
import { contentToFormData } from '@/utils/formData';
import { handleServerAction } from '@/utils/serverActionError';
import { errorToast, successToast } from '@/utils/toast';
import { handleServerResponse } from '@/utils/serverActionError';

import ResearchGroupEditor, { ResearchGroupFormData } from '../components/ResearchGroupEditor';

export default function ResearchGroupCreatePage() {
const onSubmit = async ({ image, ...requestObject }: ResearchGroupFormData) => {
const formData = contentToFormData('CREATE', { requestObject, image });
try {
handleServerAction(await postResearchGroupAction(formData));
successToast('์—ฐ๊ตฌ ์ŠคํŠธ๋ฆผ์„ ์ถ”๊ฐ€ํ–ˆ์Šต๋‹ˆ๋‹ค.');
} catch (e) {
errorToast(errorToStr(e));
}
const resp = await postResearchGroupAction(formData);
handleServerResponse(resp, { successMessage: '์—ฐ๊ตฌ ์ŠคํŠธ๋ฆผ์„ ์ถ”๊ฐ€ํ–ˆ์Šต๋‹ˆ๋‹ค.' });
};

return (
Expand Down
14 changes: 3 additions & 11 deletions app/[locale]/research/groups/edit/ResearchGroupEditPageContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import { putResearchGroupAction } from '@/actions/research';
import { ResearchGroup } from '@/apis/types/research';
import PageLayout from '@/components/layout/pageLayout/PageLayout';
import { WithLanguage } from '@/types/language';
import { errorToStr } from '@/utils/error';
import { contentToFormData } from '@/utils/formData';
import { handleServerAction } from '@/utils/serverActionError';
import { errorToast, successToast } from '@/utils/toast';
import { handleServerResponse } from '@/utils/serverActionError';

import ResearchGroupEditor, { ResearchGroupFormData } from '../components/ResearchGroupEditor';

Expand All @@ -23,14 +21,8 @@ export default function ResearchGroupEditPageContent({
image: content.image,
});

try {
handleServerAction(
await putResearchGroupAction({ ko: group.ko.id, en: group.en.id }, formData),
);
successToast('์—ฐ๊ตฌ ์ŠคํŠธ๋ฆผ์„ ์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค.');
} catch (e) {
errorToast(errorToStr(e));
}
const resp = await putResearchGroupAction({ ko: group.ko.id, en: group.en.id }, formData);
handleServerResponse(resp, { successMessage: '์—ฐ๊ตฌ ์ŠคํŠธ๋ฆผ์„ ์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค.' });
};

const defaultValues: ResearchGroupFormData = {
Expand Down
12 changes: 3 additions & 9 deletions app/[locale]/research/labs/[id]/ResearchLabDetailContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ import { Link } from '@/i18n/routing';
import PentagonLong from '@/public/image/pentagon_long.svg';
import PentagonShort from '@/public/image/pentagon_short.svg';
import { WithLanguage } from '@/types/language';
import { errorToStr } from '@/utils/error';
import useResponsive from '@/utils/hooks/useResponsive';
import { getPath } from '@/utils/page';
import { handleServerAction } from '@/utils/serverActionError';
import { handleServerResponse } from '@/utils/serverActionError';
import { replaceSpaceWithDash } from '@/utils/string';
import { errorToast, successToast } from '@/utils/toast';

import ResearchLabInfo from './ResesarchLabInfo';

Expand All @@ -33,12 +31,8 @@ export default function ResearchLabDetailContent({
const { isMobile } = useResponsive();

const handleDelete = async () => {
try {
handleServerAction(await deleteResearchLabAction(ids));
successToast('์—ฐ๊ตฌ์‹ค์„ ์‚ญ์ œํ–ˆ์Šต๋‹ˆ๋‹ค.');
} catch (e) {
errorToast(errorToStr(e));
}
const resp = await deleteResearchLabAction(ids);
handleServerResponse(resp, { successMessage: '์—ฐ๊ตฌ์‹ค์„ ์‚ญ์ œํ–ˆ์Šต๋‹ˆ๋‹ค.' });
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ import ResearchLabEditor, {
import PageLayout from '@/components/layout/pageLayout/PageLayout';
import { isLocalFile } from '@/types/form';
import { WithLanguage } from '@/types/language';
import { errorToStr } from '@/utils/error';
import { handleServerAction } from '@/utils/serverActionError';
import { handleServerResponse } from '@/utils/serverActionError';
import { encodeFormDataFileName } from '@/utils/string';
import { errorToast, successToast } from '@/utils/toast';

interface ResearchLabEditPageContentProps {
lab: WithLanguage<ResearchLab>;
Expand Down Expand Up @@ -52,18 +50,15 @@ export default function ResearchLabEditPageContent({
),
);

// attachment๊ฐ€ ์•„๋‹Œ ํŠน์ˆ˜ํ•œ key('pdf')๋ผ์„œ conentToFormData ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ  ์ง์ ‘ ๋ณ„๋„ ์ฒ˜๋ฆฌ
encodeFormDataFileName(
formData,
'pdf',
common.pdf.filter(isLocalFile).map((x) => x.file),
);

try {
handleServerAction(await putResearchLabAction({ ko: lab.ko.id, en: lab.en.id }, formData));
successToast('์—ฐ๊ตฌ์‹ค์„ ์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค.');
} catch (e) {
errorToast(errorToStr(e));
}
const resp = await putResearchLabAction({ ko: lab.ko.id, en: lab.en.id }, formData);
handleServerResponse(resp, { successMessage: '์—ฐ๊ตฌ์‹ค์„ ์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค.' });
};

const defaultValues: ResearchLabFormData = {
Expand Down
13 changes: 8 additions & 5 deletions app/[locale]/research/labs/components/ResearchLabEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ import { FormProvider, useForm } from 'react-hook-form';

import { SimpleFaculty } from '@/apis/types/people';
import { ResearchGroup } from '@/apis/types/research';
import Fieldset from '@/components/form/Fieldset';
import Form from '@/components/form/Form';
import LanguagePicker from '@/components/form/LanguagePicker';
import { researchLabs } from '@/constants/segmentNode';
import { useRouter } from '@/i18n/routing';
import { EditorFile } from '@/types/form';
import { Language, WithLanguage } from '@/types/language';
import { getPath } from '@/utils/page';

import Fieldset from '../../../../../components/form/Fieldset';
import Form from '../../../../../components/form/Form';
import LanguagePicker from '../../../../../components/form/LanguagePicker';
import { EditorFile } from '../../../../../types/form';

export type ResearchLabFormData = WithLanguage<{
name: string;
description: string;
Expand Down Expand Up @@ -109,6 +108,8 @@ const Editor = ({
{ label: '์„ ํƒ ์•ˆ ํ•จ', value: null },
...professors[language].map((prof) => ({ label: prof.name, value: prof.id })),
]}
borderStyle="border-neutral-300"
height="h-8"
/>
</Fieldset>
<Fieldset title="์—ฐ๊ตฌ์‹ค ์•ฝ์ž" mb="mb-11" titleMb="mb-2">
Expand Down Expand Up @@ -140,6 +141,8 @@ const Editor = ({
...groups[language].map((lab) => ({ label: `${lab.name} ์ŠคํŠธ๋ฆผ`, value: lab.id })),
]}
rules={{ required: true }}
borderStyle="border-neutral-300"
height="h-8"
/>
</Fieldset>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ import ResearchLabEditor, {
import PageLayout from '@/components/layout/pageLayout/PageLayout';
import { isLocalFile } from '@/types/form';
import { WithLanguage } from '@/types/language';
import { errorToStr } from '@/utils/error';
import { handleServerAction } from '@/utils/serverActionError';
import { handleServerResponse } from '@/utils/serverActionError';
import { encodeFormDataFileName } from '@/utils/string';
import { errorToast, successToast } from '@/utils/toast';

interface ResearchLabCreatePageContentProps {
groups: WithLanguage<ResearchGroup[]>;
Expand All @@ -38,18 +36,15 @@ export default function ResearchLabCreatePageContent({
),
);

// attachment๊ฐ€ ์•„๋‹Œ ํŠน์ˆ˜ํ•œ key('pdf')๋ผ์„œ conentToFormData ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ  ์ง์ ‘ ๋ณ„๋„ ์ฒ˜๋ฆฌ
encodeFormDataFileName(
formData,
'pdf',
common.pdf.filter(isLocalFile).map((x) => x.file),
);

try {
handleServerAction(await postResearchLabAction(formData));
successToast('์—ฐ๊ตฌ์‹ค์„ ์ถ”๊ฐ€ํ–ˆ์Šต๋‹ˆ๋‹ค.');
} catch (e) {
errorToast(errorToStr(e));
}
const resp = await postResearchLabAction(formData);
handleServerResponse(resp, { successMessage: '์—ฐ๊ตฌ์‹ค์„ ์ถ”๊ฐ€ํ–ˆ์Šต๋‹ˆ๋‹ค.' });
};

return (
Expand Down
4 changes: 2 additions & 2 deletions components/layout/pageLayout/PageLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ export default function PageLayout({
<div
className={clsx('relative grow bg-white', {
'p-0': removePadding,
'pt-0': removeTopPadding,
'pb-0': removeBottomPadding,
'p-[0_1.25rem_4rem_1.25rem] sm:p-[0_360px_150px_100px]': removeTopPadding,
'p-[1.75rem_1.25rem_0_1.25rem] sm:p-[2.75rem_360px_0_100px]': removeBottomPadding,
'p-[1.75rem_1.25rem_4rem_1.25rem] sm:p-[2.75rem_360px_150px_100px]':
!removePadding && !removeTopPadding && !removeBottomPadding,
})}
Expand Down

0 comments on commit caa5f91

Please sign in to comment.