-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of https://github.com/FRONTENDSCHOOL5/final-17…
…-breath-connect into develop
- Loading branch information
Showing
10 changed files
with
263 additions
and
292 deletions.
There are no files selected for viewing
File renamed without changes.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,63 @@ | ||
import React from 'react'; | ||
import styled, { css } from 'styled-components'; | ||
import AddImg from '../../assets/sprite/img-btn.svg'; | ||
import AddDarkImg from '../../assets/sprite/img-btn-dark.svg'; | ||
import BasicProfileImg from '../../assets/images/basic-profile-l.svg'; | ||
|
||
const ProfileImage = ({ previewImage, handleImage }) => { | ||
return ( | ||
<> | ||
<Label htmlFor="image" > | ||
<Image src={previewImage ? previewImage : BasicProfileImg} alt="사용자 프로필 이미지" /> | ||
</Label> | ||
<ImageInput | ||
type="file" | ||
accept="image/png, image/jpg, image/jpeg" | ||
id="image" | ||
onChange={handleImage} | ||
/> | ||
</> | ||
) | ||
} | ||
|
||
export default ProfileImage; | ||
|
||
const Label = styled.label` | ||
display: block; | ||
position: relative; | ||
width: 11rem; | ||
height: 11rem; | ||
margin: 3.5rem auto 5.5rem; | ||
border: 1px solid ${({ theme }) => theme.colors.placeHolderColor}; | ||
border-radius: 50%; | ||
cursor: pointer; | ||
&::after { | ||
content: ''; | ||
display: block; | ||
position: absolute; | ||
right: 0; | ||
bottom: 0; | ||
width: 3.6em; | ||
height: 3.6rem; | ||
background: url(${AddImg}) no-repeat center / 3.6rem 3.6rem; | ||
z-index: 2; | ||
${({ isDarkMode }) => isDarkMode && css` | ||
background: url(${AddDarkImg}) no-repeat center / 3.6rem 3.6rem; | ||
`} | ||
} | ||
` | ||
|
||
const Image = styled.img` | ||
width: 100%; | ||
height: 100%; | ||
border-radius: 50%; | ||
object-fit: cover; | ||
` | ||
|
||
const ImageInput = styled.input` | ||
position: absolute; | ||
width: 0.1rem; | ||
height: 0.1rem; | ||
z-index: -1000rem; | ||
` |
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 |
---|---|---|
|
@@ -21,5 +21,5 @@ export const MESSAGE = { | |
ACCOUNTNAME: { | ||
REQUIRED: '계정 ID를 입력해주세요', | ||
PATTERN: '영문, 숫자, 특수문자 ., _ 만 입력해주세요' | ||
} | ||
}, | ||
} |
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,58 @@ | ||
import { useState } from 'react'; | ||
import { useMutation } from 'react-query'; | ||
import { postUploadProfile } from '../api/auth'; | ||
import imageCompression from 'browser-image-compression'; | ||
|
||
const useImageUpload = () => { | ||
const [previewImage, setPreviewImage] = useState(''); | ||
const [image, setImage] = useState(''); | ||
|
||
const uploadImage = useMutation('uploadImage', postUploadProfile, { | ||
onSuccess: (res) => { | ||
console.log(res); | ||
setImage(process.env.REACT_APP_API_URL + res.filename); | ||
}, | ||
onError: (error) => { | ||
console.log(error); | ||
} | ||
}); | ||
|
||
const handleImage = async (e) => { | ||
const file = e.target.files[0]; | ||
const allowedExtensions = ['jpg', 'gif', 'png', 'jpeg', 'bmp', 'tif', 'heic']; | ||
const fileExtension = file.name.split('.').pop().toLowerCase(); | ||
|
||
if (allowedExtensions.includes(fileExtension)) { | ||
try { | ||
const options = { | ||
maxSizeMB: 1, | ||
maxWidthOrHeight: 800, | ||
useWebWorker: true, | ||
}; | ||
|
||
const compressedImage = await imageCompression(file, options); | ||
const compressedFile = new File([compressedImage], compressedImage.name, { | ||
type: compressedImage.type, | ||
}); | ||
|
||
const imgData = new FormData(); | ||
imgData.append('image', compressedFile); | ||
await uploadImage.mutate(imgData); | ||
|
||
const reader = new FileReader(); | ||
reader.readAsDataURL(compressedFile); | ||
reader.onload = () => { | ||
setPreviewImage(reader.result); | ||
}; | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
} else { | ||
alert('유효하지 않은 파일 형식입니다.'); | ||
} | ||
}; | ||
|
||
return { image, previewImage, handleImage }; | ||
}; | ||
|
||
export default useImageUpload; |
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 React, { useState, useEffect } from 'react'; | ||
|
||
export default function useValid(formData) { | ||
const [messages, setMessages] = useState({ | ||
email: '', | ||
password: '' | ||
}); | ||
const [isValid, setIsValid] = useState({ | ||
email: false, | ||
password: false | ||
}); | ||
|
||
useEffect(() => { | ||
if (formData.email) { | ||
const emailRegex = /^[a-zA-Z0-9+-\_.]+@[a-zA-Z0-9-]+\.[a-zAZ0-9-.]+$/; | ||
if (!emailRegex.test(formData.email)) { | ||
setMessages((prevMessages) => ({ | ||
...prevMessages, | ||
email: '이메일의 형식이 올바르지 않습니다 😥' | ||
})); | ||
setIsValid({ ...isValid, email: false }); | ||
} else { | ||
setMessages((prevMessages) => ({ | ||
...prevMessages, | ||
email: '' | ||
})); | ||
setIsValid({ ...isValid, email: true }); | ||
} | ||
} else { | ||
setMessages((prevMessages) => ({ | ||
...prevMessages, | ||
email: '' | ||
})); | ||
setIsValid({ ...isValid, email: false }); | ||
} | ||
}, [formData.email]); | ||
|
||
useEffect(() => { | ||
if (formData.password) { | ||
const passwordRegex = | ||
/^(?=.*[A-Za-z])(?=.*\d)(?=.*[$@$!%*#?&])[A-Za-z\d$@$!%*#?&]{6,}$/; | ||
if (!passwordRegex.test(formData.password)) { | ||
setMessages((prevMessages) => ({ | ||
...prevMessages, | ||
password: '영문+숫자+특수기호 조합으로 6자리 이상 입력해주세요' | ||
})); | ||
setIsValid({ ...isValid, password: false }); | ||
} else { | ||
setMessages((prevMessages) => ({ | ||
...prevMessages, | ||
password: '' | ||
})); | ||
setIsValid({ ...isValid, password: true }); | ||
} | ||
} else { | ||
setMessages((prevMessages) => ({ | ||
...prevMessages, | ||
password: '' | ||
})); | ||
setIsValid({ ...isValid, password: false }); | ||
} | ||
}, [formData.password]); | ||
|
||
return { messages, setMessages, isValid, setIsValid }; | ||
} |
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
Oops, something went wrong.