Skip to content

Commit

Permalink
[ feat ] wishes create 페이지 최적화
Browse files Browse the repository at this point in the history
  • Loading branch information
myeongheonhong committed Oct 25, 2024
1 parent f04f148 commit 98ac0b7
Show file tree
Hide file tree
Showing 19 changed files with 475 additions and 352 deletions.
Binary file modified .yarn/install-state.gz
Binary file not shown.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"test:watch": "jest --watchAll"
},
"dependencies": {
"@hookform/resolvers": "^3.9.0",
"@next/bundle-analyzer": "^13.4.19",
"@nextui-org/skeleton": "^2.0.32",
"axios": "^1.3.5",
Expand All @@ -26,7 +27,8 @@
"recoil": "^0.7.7",
"recoil-persist": "^4.2.0",
"tailwind-styled-components": "^2.2.0",
"ts-node": "^10.9.2"
"ts-node": "^10.9.2",
"yup": "^1.4.0"
},
"devDependencies": {
"@testing-library/dom": "^10.4.0",
Expand Down
24 changes: 18 additions & 6 deletions src/api/common/axios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ client.interceptors.response.use(
},
async function (error: any) {
const originalRequest = error.config;
let retryFlg = false;

if (retryFlg) {
return Promise.reject(error); // 이미 재시도된 요청은 다시 재시도하지 않음
}

// 토큰 만료 시 처리
if (error.response && error.response.data.message === '유효하지 않은 토큰입니다.') {
Expand All @@ -51,17 +56,24 @@ client.interceptors.response.use(
refreshToken: refreshToken,
};

await fetch('http://localhost:8080/api/set-cookies', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
console.log(accessToken);
console.log(loginUserCookiesData);

await axios.post(
'http://localhost:8080/api/set-cookies',
JSON.stringify(newCookiesData),
{
headers: {
'Content-Type': 'application/json',
},
},
body: JSON.stringify(newCookiesData),
});
);

// 3. 갱신된 토큰을 헤더에 추가
originalRequest.headers['Authorization'] = `Bearer ${accessToken}`;

retryFlg = true;

// 4. 원래 요청 재시도
return client(originalRequest);
} else {
Expand Down
1 change: 1 addition & 0 deletions src/app/wishes/create/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default function WishesCreatePage({
searchParams: { step: WishesCreateStepType; wishTitle: string };
}) {
const { step, wishTitle } = searchParams;

if ((step !== 'link' && step !== 'account') || wishTitle === '') {
return <ErrorPage />;
}
Expand Down
24 changes: 2 additions & 22 deletions src/components/Common/Calendar/Calendar.tsx
Original file line number Diff line number Diff line change
@@ -1,40 +1,20 @@
import Image from 'next/image';
import { ko } from 'date-fns/locale';
import { UseFormReturn, useWatch } from 'react-hook-form';
import DatePicker from 'react-datepicker';
import 'react-datepicker/dist/react-datepicker.css';
import CalendarHeader from './CalendarHeader';
import { getDate } from '@/utils/common/getDate';
import { CalendarGreyIc, CalendarIc } from '../../../../public/assets/icons';

import Box from '../Box';
import { WishesLinkDataType } from '@/types/input';

interface CalendarProps {
date: Date;
methods: UseFormReturn<WishesLinkDataType, any, undefined>;
handleChangeDate?: (selectedDate: Date) => void;
readOnly?: boolean;
}

export default function Calendar(props: CalendarProps) {
const { date, methods, readOnly } = props;

const control = methods.control;

const watchStartDateData = useWatch({
control,
name: 'startDate',
});

const watchEndDateData = useWatch({
control,
name: 'endDate',
});

const handleChangeDate = (selectedDate: Date) => {
methods.setValue('startDate', selectedDate);
methods.setValue('endDate', getDate(selectedDate, 7));
};
const { date, handleChangeDate, readOnly } = props;

return (
<Box bgColor="dark_green" fontColor={readOnly ? 'gray2' : 'white'}>
Expand Down
28 changes: 16 additions & 12 deletions src/components/UI/InputTextForm.tsx
Original file line number Diff line number Diff line change
@@ -1,42 +1,46 @@
import { useFormContext, useWatch } from 'react-hook-form';
import { RegisterOptions, useFormContext, UseFormRegisterReturn, useWatch } from 'react-hook-form';
import InputForm from './InputForm';
import InputText from '../Common/Input/inputText';
import InputTextarea from '../Common/Input/inputTextarea';
import { memo, ReactNode } from 'react';
import { ReactNode } from 'react';

export default function InputTextForm<T>({
inputType,
inputTitle,
register,
registerName,
validate,
placeholder,
maxLength,
children,
}: {
inputType: 'text' | 'textarea';
inputTitle: string;
registerName: keyof T;
register: UseFormRegisterReturn<keyof T & string>;
registerName?: keyof T;
validate?: RegisterOptions;
placeholder?: string;
maxLength?: number;
children?: ReactNode;
}) {
const { register, control } = useFormContext();
// const { register, control } = useFormContext();

const text = useWatch({
control,
name: registerName as string,
}) as string;
// const text = useWatch({
// control,
// name: registerName as string,
// }) as string;

return (
<InputForm title={inputTitle}>
{inputType === 'text' ? (
<InputText register={register(registerName as string)} placeholder={placeholder}>
<InputText register={register} placeholder={placeholder}>
{children}
{maxLength && <TextCount textLength={text.length} maxLength={maxLength} />}
{/* {maxLength && <TextCount textLength={text.length} maxLength={maxLength} />} */}
</InputText>
) : (
<InputTextarea register={register(registerName as string)} placeholder={placeholder}>
<InputTextarea register={register} placeholder={placeholder}>
{children}
{maxLength && <TextCount textLength={text.length} maxLength={maxLength} />}
{/* {maxLength && <TextCount textLength={text.length} maxLength={maxLength} />} */}
</InputTextarea>
)}
</InputForm>
Expand Down
80 changes: 56 additions & 24 deletions src/components/UI/UploadImageBox.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,68 @@
'use client';

// import Image from 'next/image';
// import { UploadImageLogoIc } from '../../../public/assets/icons';

// export function UploadImageBox({
// imageUrl,
// handleUploadImageFile,
// }: {
// imageUrl: string;
// handleUploadImageFile?: (e: React.ChangeEvent<HTMLInputElement>) => void;
// }) {
// return (
// <label>
// <div className="flex justify-center items-center w-full h-220 bg-dark_green text-gray2 rounded-xl relative">
// {imageUrl ? (
// <Image src={imageUrl} alt="등록한 사진 이미지" fill />
// ) : (
// <Image src={UploadImageLogoIc} alt="파일 업로드 아이콘" width={70} />
// // 이미지가 (덜커덩 거리면서 등록되는거)이상하게 등록되는거 수정해야됩니다.
// )}
// </div>

// <input
// className="hidden"
// type="file"
// accept=".jpg,.jpeg,.png"
// onChange={handleUploadImageFile}
// disabled={handleUploadImageFile === undefined}
// readOnly
// />
// </label>
// );
// }

import React from 'react';
import Image from 'next/image';
import { UploadImageLogoIc } from '../../../public/assets/icons';
import { Suspense } from 'react';

export function UploadImageBox({
imageURL,
export const UploadImageBox = React.memo(function UploadImageBox({
imageUrl,
handleUploadImageFile,
}: {
imageURL: string;
imageUrl: string;
handleUploadImageFile?: (e: React.ChangeEvent<HTMLInputElement>) => void;
}) {
return (
<Suspense>
<label>
<div className="flex justify-center items-center w-full h-220 bg-dark_green text-gray2 rounded-xl">
{imageURL ? (
<Image src={imageURL} alt="등록한 사진 이미지" width={100} height={100} />
) : (
<Image src={UploadImageLogoIc} alt="파일 업로드 아이콘" />
)}
</div>
<label>
<div className="flex justify-center items-center w-full h-220 bg-dark_green text-gray2 rounded-xl relative">
{imageUrl ? (
<Image src={imageUrl} alt="등록한 사진 이미지" fill />
) : (
<Image src={UploadImageLogoIc} alt="파일 업로드 아이콘" width={70} />
// 이미지가 (덜커덩 거리면서 등록되는거)이상하게 등록되는거 수정해야됩니다.
)}
</div>

<input
className="hidden"
type="file"
accept=".jpg,.jpeg,.png"
onChange={handleUploadImageFile}
disabled={handleUploadImageFile === undefined}
readOnly
/>
</label>
</Suspense>
<input
className="hidden"
type="file"
accept=".jpg,.jpeg,.png"
onChange={handleUploadImageFile}
disabled={handleUploadImageFile === undefined}
readOnly
/>
</label>
);
}
});
19 changes: 19 additions & 0 deletions src/constant/init.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { WishesAccountDataType, WishesLinkDataType } from '@/types/input';
import { getDate } from '@/utils/common/getDate';

export const wishesLinkInputInit: WishesLinkDataType = {
imageUrl: '',
title: '',
hint: '',
startDate: new Date(),
endDate: getDate(new Date(), 7),
wantsGift: false,
};

export const wishesAccountInputInit: WishesAccountDataType = {
name: '',
account: '',
bank: '',
phone: '',
noticeAgree: false,
};
20 changes: 10 additions & 10 deletions src/container/login/oauth2/code/kakao/container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import Loading from '@/app/loading';
import { LoginUserDataType } from '@/utils/common/cookies';
import axios from 'axios';
import { useRouter } from 'next/navigation';
import { useEffect } from 'react';

Expand All @@ -11,19 +12,18 @@ export default function LoginContainer({ loginUserData }: { loginUserData?: Logi
if (!loginUserData) {
alert('카카오 로그인 에러');
router.push('/');
return <Loading />;
}

useEffect(() => {
fetch('http://localhost:8080/api/set-cookies', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(loginUserData),
}).then(() => {
router.push('/wishes');
});
axios
.post('http://localhost:8080/api/set-cookies', JSON.stringify(loginUserData), {
headers: {
'Content-Type': 'application/json',
},
})
.then(() => {
router.push('/wishes');
});
}, []);

return <Loading />;
Expand Down
2 changes: 1 addition & 1 deletion src/container/present/server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function MessageFromWisheMaker({ wishId }: { wishId: string }) {

{/* 이미지값 넣어줘야해요! */}
<div className="mb-30">
<UploadImageBox imageURL={''} />
<UploadImageBox imageUrl={''} />
</div>
</>
);
Expand Down
Loading

0 comments on commit 98ac0b7

Please sign in to comment.