Skip to content

Commit

Permalink
chore: 대소문자 변경 기록추가
Browse files Browse the repository at this point in the history
  • Loading branch information
bae-sh committed Jan 15, 2024
1 parent 3d2a04e commit 361ad44
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 0 deletions.
Binary file added client/.storybook/public/images/advertise.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/.storybook/public/images/google_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/.storybook/public/images/main-duck.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/.storybook/public/images/user_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
100 changes: 100 additions & 0 deletions client/src/hooks/form/useEmail.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// react, next
import React, { useState, useRef } from 'react';

// 전역
import useModal from '@/hooks/modal/useModal';

// types
import { EmailState, EmailType } from '@/types';

// constant
import { ModalType, successMessage, errorMessage } from '@/constants/constant';

// services
import { emailManager } from '@/service/email';

function useEmail(type: EmailType) {
const { openModal } = useModal();

const certificateRef = useRef<HTMLInputElement>(null);
const [certificateNumber, setCertificationNumber] = useState<string>('');

const [emailState, setEmailState] = useState<EmailState>(EmailState.None);
const [emailAuthToken, setEmailAuthToken] = useState<string>('');

const handleChangeCertifiactionNumber = (
e: React.ChangeEvent<HTMLInputElement>
) => {
setCertificationNumber(e.target.value);
};

const handleRequestEmail = async (email: string) => {
setEmailState(EmailState.Submitting);
try {
switch (type) {
case 'SIGNUP': {
await emailManager.sendSignUpEmail({ email });
break;
}
default: {
await emailManager.sendProfileEmail({ email });
}
}
setEmailState(EmailState.Submitted);
openModal({
type: ModalType.SUCCESS,
message: successMessage.sendingEmailSuccess,
});
} catch {
openModal({
type: ModalType.ERROR,
message: errorMessage.failedSendingEmail,
});
setEmailState(EmailState.None);
}
};

const handleCheckEmail = async (email: string) => {
let token = '';
try {
switch (type) {
case 'SIGNUP': {
token = await emailManager.checkSignUpNumber({
email,
number: parseInt(certificateNumber),
});
break;
}
default: {
token = await emailManager.checkProfileEmailNumber({
email,
number: parseInt(certificateNumber),
type,
});
}
}
setEmailAuthToken(token);
openModal({
type: ModalType.SUCCESS,
message: successMessage.confirmNumberSuccess,
});
} catch {
setEmailAuthToken('');
openModal({
type: ModalType.ERROR,
message: errorMessage.notmatchConfirmNumber,
});
}
};

return {
certificateRef,
emailState,
emailAuthToken,
handleChangeCertifiactionNumber,
handleRequestEmail,
handleCheckEmail,
};
}

export default useEmail;
55 changes: 55 additions & 0 deletions client/src/hooks/form/useInputImage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// react, next
import React, { useState, useRef } from 'react';

// constant
import { IMAGE_FILE_MAX_SIZE } from '@/constants/constant';

// services
import { BASE_URL } from '@/service/base/api';

function useInputImage(initialProfileImg?: string) {
const imgRef = useRef<HTMLInputElement>(null);

const [profileImg, setProfileImg] = useState<string>(
`${BASE_URL}${initialProfileImg || ''}`
);
const [imgFile, setImgFile] = useState<Blob | null>(null);

const handleChooseFile = () => {
imgRef.current?.click();
};

const handleImgInput = (e: React.ChangeEvent<HTMLInputElement>) => {
if (e.target.files && e.target.files.length !== 0) {
const file = e.target.files[0];
const fileSize = file.size;
if (fileSize > IMAGE_FILE_MAX_SIZE) {
alert('이미지 파일 용량 초과');
return;
}
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onloadend = () => {
// null 방지
if (reader.result) {
if (typeof reader.result === 'string') {
setImgFile(file);
setProfileImg(reader.result);
} else {
// ArrayBuffer인 경우 string으로 변경
setProfileImg(
String.fromCharCode.apply(
null,
Array.from(new Uint16Array(reader.result))
)
);
}
}
};
}
};

return { imgRef, profileImg, imgFile, handleChooseFile, handleImgInput };
}

export default useInputImage;

0 comments on commit 361ad44

Please sign in to comment.