-
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
174 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { endPoint } from 'constants/endPoint'; | ||
import { tokenAxios } from 'utils'; | ||
|
||
export const requestPostConcertRecord = async (formData: FormData) => { | ||
return await tokenAxios.post(`${endPoint.CREATE_CONCERT_RECORD}`, formData); | ||
}; |
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
65 changes: 65 additions & 0 deletions
65
src/pages/createConcertRecord/components/RecordSubmitDialog.tsx
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,65 @@ | ||
import styled from '@emotion/styled'; | ||
import { useNavigate } from 'react-router-dom'; | ||
|
||
import BaseButton from 'components/buttons/BaseButton'; | ||
import Dialog from 'components/dialog/Dialog'; | ||
import { usePostConcertRecord } from 'queries/concertRecord'; | ||
import { useModalStore } from 'stores'; | ||
import { TitleText2 } from 'styles/Typography'; | ||
import type { ConcertRecord } from 'types'; | ||
|
||
interface RecordSubmitDialogProps { | ||
recordData: ConcertRecord; | ||
} | ||
|
||
const DialogContainer = styled.div` | ||
position: absolute; | ||
z-index: 1004; | ||
`; | ||
|
||
const RecordSubmitDialog = ({ recordData }: RecordSubmitDialogProps) => { | ||
const { closeModal } = useModalStore(['closeModal']); | ||
const { mutate } = usePostConcertRecord(); | ||
const navigate = useNavigate(); | ||
|
||
const handleSubmitSuccess = () => { | ||
navigate('/concert-record'); | ||
closeModal('dialog', 'confirm'); | ||
}; | ||
|
||
const handleApplyClick = () => { | ||
mutate(recordData, { onSuccess: handleSubmitSuccess }); | ||
}; | ||
|
||
return ( | ||
<DialogContainer> | ||
<Dialog> | ||
<Dialog.Content> | ||
<TitleText2>공연 기록을 등록하시겠습니까?</TitleText2> | ||
</Dialog.Content> | ||
<Dialog.Button> | ||
<BaseButton | ||
color="primary" | ||
isFullWidth={false} | ||
onClick={() => closeModal('dialog', 'confirm')} | ||
size="small" | ||
variant="outline" | ||
> | ||
취소 | ||
</BaseButton> | ||
<BaseButton | ||
color="primary" | ||
isFullWidth={false} | ||
onClick={handleApplyClick} | ||
size="small" | ||
variant="fill" | ||
> | ||
등록 | ||
</BaseButton> | ||
</Dialog.Button> | ||
</Dialog> | ||
</DialogContainer> | ||
); | ||
}; | ||
|
||
export default RecordSubmitDialog; |
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 @@ | ||
export * from './usePostConcertRecord'; |
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,31 @@ | ||
import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
|
||
import { requestPostConcertRecord } from 'api'; | ||
import type { ConcertRecord } from 'types'; | ||
|
||
const postFormData = async (recordFormData: ConcertRecord) => { | ||
const formData = new FormData(); | ||
const { images, ...rest } = recordFormData; | ||
|
||
images.forEach((file) => { | ||
formData.append('images', file); | ||
}); | ||
|
||
formData.append('request', JSON.stringify(rest)); | ||
|
||
return await requestPostConcertRecord(formData); | ||
}; | ||
|
||
export const usePostConcertRecord = () => { | ||
const queryClient = useQueryClient(); | ||
|
||
return useMutation({ | ||
mutationFn: postFormData, | ||
onSuccess: async () => { | ||
await queryClient.invalidateQueries({ queryKey: ['recordList'] }); | ||
}, | ||
onError: (err) => { | ||
console.log('폼 전송 오류: ', err); | ||
}, | ||
}); | ||
}; |
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,24 @@ | ||
import { z } from 'zod'; | ||
|
||
const requiredString = () => z.string().min(1, '필수 입력 항목입니다.'); | ||
const requiredNumber = () => z.number().positive('필수 입력 항목입니다.'); | ||
const requiredFiles = () => | ||
z | ||
.array( | ||
z.instanceof(File).refine((file) => file instanceof File, { | ||
message: '파일을 업로드해야 합니다.', | ||
}) | ||
) | ||
.optional() | ||
.default([]); | ||
|
||
export const concertRecordSchema = z.object({ | ||
concertId: requiredNumber(), | ||
date: requiredString(), | ||
episode: requiredString(), | ||
content: requiredString(), | ||
seatName: requiredString(), | ||
images: requiredFiles(), | ||
}); | ||
|
||
export type ConcertRecordSchemaType = z.infer<typeof concertRecordSchema>; |
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