-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
186 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
import { getRequest } from '@/apis'; | ||
import { getRequest, putRequest } from '@/apis'; | ||
import { Attachment } from '@/apis/types/attachment'; | ||
|
||
type Response = { | ||
export type CouncilRules = { | ||
constitution: { type: string; attachments: Attachment[] }; | ||
bylaw: { type: string; attachments: Attachment[] }; | ||
}; | ||
|
||
export const getCouncilRule = () => getRequest<Response>('/v2/council/rule', undefined); | ||
export const getCouncilRules = () => getRequest<CouncilRules>('/v2/council/rule', undefined); | ||
|
||
export const putCouncilRules = (type: keyof CouncilRules, body: FormData) => | ||
putRequest<CouncilRules>(`/v2/council/rule/${type}`, { body, jsessionID: true }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
'use client'; | ||
|
||
import { FormProvider, useForm } from 'react-hook-form'; | ||
|
||
import { putCouncilRulesAction } from '@/actions/council'; | ||
import { CouncilRules } from '@/apis/v2/council/rule'; | ||
import Form from '@/components/form/Form'; | ||
import { useRouter } from '@/i18n/routing'; | ||
import { EditorFile } from '@/types/form'; | ||
import { | ||
attachmentsToEditorFiles, | ||
contentToFormData, | ||
getAttachmentDeleteIds, | ||
} from '@/utils/formData'; | ||
|
||
interface FormData { | ||
constitutionAttachments: EditorFile[]; | ||
bylawAttachments: EditorFile[]; | ||
} | ||
|
||
interface Props { | ||
councilRules: CouncilRules; | ||
} | ||
|
||
export default function CouncilByLawsEditClientPage({ councilRules }: Props) { | ||
const constitutionAttachments = councilRules.constitution.attachments; | ||
const bylawAttachments = councilRules.bylaw.attachments; | ||
|
||
const methods = useForm<FormData>({ | ||
defaultValues: { | ||
constitutionAttachments: attachmentsToEditorFiles(constitutionAttachments), | ||
bylawAttachments: attachmentsToEditorFiles(bylawAttachments), | ||
}, | ||
}); | ||
const router = useRouter(); | ||
|
||
const { | ||
handleSubmit, | ||
formState: { dirtyFields }, | ||
} = methods; | ||
|
||
const onCancel = () => { | ||
router.back(); | ||
}; | ||
|
||
const onSubmit = handleSubmit(async (formData: FormData) => { | ||
const bylawsFormData = dirtyFields.bylawAttachments | ||
? (() => { | ||
const bylawsDeleteIds = getAttachmentDeleteIds( | ||
formData.bylawAttachments, | ||
bylawAttachments, | ||
); | ||
return contentToFormData('EDIT', { | ||
requestObject: { deleteIds: bylawsDeleteIds }, | ||
attachments: formData.bylawAttachments, | ||
}); | ||
})() | ||
: undefined; | ||
|
||
const constitutionFormData = dirtyFields.constitutionAttachments | ||
? (() => { | ||
const constitutionDeleteIds = getAttachmentDeleteIds( | ||
formData.constitutionAttachments, | ||
constitutionAttachments, | ||
); | ||
return contentToFormData('EDIT', { | ||
requestObject: { deleteIds: constitutionDeleteIds }, | ||
attachments: formData.constitutionAttachments, | ||
}); | ||
})() | ||
: undefined; | ||
|
||
await putCouncilRulesAction(bylawsFormData, constitutionFormData); | ||
}); | ||
|
||
return ( | ||
<FormProvider {...methods}> | ||
<Form> | ||
<Form.Section title="학생회칙" mb="mb-10" titleMb="mb-2"> | ||
<Form.File name="constitutionAttachments" multiple rules={{ required: true }} /> | ||
</Form.Section> | ||
|
||
<Form.Section title="세칙" titleMb="mb-2"> | ||
<Form.File name="bylawAttachments" multiple rules={{ required: true }} /> | ||
</Form.Section> | ||
|
||
<Form.Action onCancel={onCancel} onSubmit={onSubmit} /> | ||
</Form> | ||
</FormProvider> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { getCouncilRules } from '@/apis/v2/council/rule'; | ||
import CouncilByLawsEditClientPage from '@/app/[locale]/community/council/rules/edit/client'; | ||
import PageLayout from '@/components/layout/pageLayout/PageLayout'; | ||
|
||
export default async function CouncilBylawsEditPage() { | ||
const councilRules = await getCouncilRules(); | ||
|
||
return ( | ||
<PageLayout title="학생 회칙 및 세칙 수정" titleType="big" hideNavbar> | ||
<CouncilByLawsEditClientPage councilRules={councilRules} /> | ||
</PageLayout> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters