-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#26] feat: Video src, description, category upload implemented
- Loading branch information
1 parent
ee240cc
commit bda5eba
Showing
6 changed files
with
112 additions
and
10 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,7 @@ | ||
export type uploadDto = { | ||
userId: string; | ||
describe: string; | ||
category: string; | ||
description?: string; | ||
video: string; | ||
}; |
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,10 @@ | ||
import customAxios from 'lib/axios'; | ||
import { uploadDto } from './upload.dto'; | ||
|
||
const upload = async (dto: uploadDto) => { | ||
const data = await customAxios.post('/videos', dto); | ||
|
||
return data; | ||
}; | ||
|
||
export default upload; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { useCallback, useState } from 'react'; | ||
import upload from 'api/upload/upload'; | ||
import useProfile from 'hooks/useProfile/useProfile'; | ||
import { uploadDto } from 'api/upload/upload.dto'; | ||
|
||
import { useRecoilValue } from 'recoil'; | ||
import { uploadSelectedFile } from 'atom/uploadSelectedFile'; | ||
import { myProfileAtom } from 'atom/profileAtom'; | ||
|
||
const useUpload = () => { | ||
const myProfile = useRecoilValue(myProfileAtom); | ||
const selectedFile = useRecoilValue(uploadSelectedFile); | ||
const [uploadObj, setUploadObj] = useState<uploadDto>({ | ||
userId: myProfile?.id || '', | ||
describe: '', | ||
category: '', | ||
description: '', | ||
video: (selectedFile as string) || '', | ||
}); | ||
const { handleMyProfile } = useProfile(); | ||
|
||
const [uploadErrorStatus, setUploadErrorStatus] = useState<number>(0); | ||
|
||
const handleUpload = useCallback(async () => { | ||
try { | ||
const res = await upload(uploadObj); | ||
const { data, status } = res; | ||
|
||
if (status === 400) { | ||
throw new Error('잘못된 입력'); | ||
} | ||
if (status === 401) { | ||
throw new Error('권한이 없음'); | ||
} | ||
|
||
await handleMyProfile(); | ||
|
||
return data; | ||
} catch (err) { | ||
const { status } = err.response; | ||
setUploadErrorStatus(status); | ||
return err; | ||
} | ||
}, [handleMyProfile, uploadObj]); | ||
|
||
return { | ||
uploadObj, | ||
setUploadObj, | ||
handleUpload, | ||
uploadErrorStatus, | ||
}; | ||
}; | ||
|
||
export default useUpload; |