-
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.
Merge pull request #282 from Anifriends/develop
release: v0.1.6
- Loading branch information
Showing
14 changed files
with
188 additions
and
79 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Flex, Spinner } from '@chakra-ui/react'; | ||
|
||
export default function Loader() { | ||
return ( | ||
<Flex justify="center" align="center"> | ||
<Spinner | ||
thickness="4px" | ||
speed="0.65s" | ||
emptyColor="gray.200" | ||
color="orange.400" | ||
size="xl" | ||
/> | ||
</Flex> | ||
); | ||
} |
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,60 @@ | ||
import { useToast, UseToastOptions } from '@chakra-ui/react'; | ||
import { useState } from 'react'; | ||
|
||
import { uploadImage } from '../apis/common/Image'; | ||
import { resizeImageFile } from '../utils/image'; | ||
|
||
const toastOption = ( | ||
description: string, | ||
status: UseToastOptions['status'], | ||
): UseToastOptions => { | ||
return { | ||
description, | ||
position: 'top', | ||
status, | ||
duration: 1500, | ||
isClosable: true, | ||
}; | ||
}; | ||
|
||
export const usePhotoUpload = (initialPhoto?: string) => { | ||
const [photo, setPhoto] = useState<string | undefined>(initialPhoto); | ||
|
||
const toast = useToast(); | ||
|
||
const handleUploadPhoto = async (files: FileList | null) => { | ||
if (!files) { | ||
return; | ||
} | ||
|
||
if (files.length !== 1) { | ||
toast(toastOption('프로필 이미지는 한 장만 등록 가능합니다.', 'error')); | ||
|
||
return; | ||
} | ||
|
||
const imageFile = files[0]; | ||
const localImageUrl = URL.createObjectURL(imageFile); | ||
setPhoto(localImageUrl); | ||
|
||
const resizedImage = await resizeImageFile(imageFile, 2); | ||
const formData = new FormData(); | ||
formData.append('images', resizedImage); | ||
|
||
const { data } = await uploadImage(formData); | ||
const [imageUrl] = data.imageUrls; | ||
|
||
setPhoto(imageUrl); | ||
}; | ||
|
||
const handleDeletePhoto = () => { | ||
setPhoto(undefined); | ||
}; | ||
|
||
return { | ||
photo, | ||
setPhoto, | ||
handleUploadPhoto, | ||
handleDeletePhoto, | ||
}; | ||
}; |
Oops, something went wrong.
0a3ed36
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
anifriends-frontend-volunteer – ./apps/volunteer
anifriends-frontend-volunteer-git-main-dongja.vercel.app
anifriends-frontend-volunteer-dongja.vercel.app
anifriends-frontend-volunteer.vercel.app