Skip to content

Commit

Permalink
공통 컴포넌트 및 리뷰 관련 리팩토링
Browse files Browse the repository at this point in the history
공통 컴포넌트 및 리뷰 관련 리팩토링
  • Loading branch information
hyeonjun-L authored Mar 18, 2024
2 parents 2c8a38c + fa4930c commit fe92b75
Show file tree
Hide file tree
Showing 116 changed files with 1,015 additions and 2,413 deletions.
11 changes: 6 additions & 5 deletions src/app/(auth)/_components/Register/Steps/UserConsentForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useForm, Controller } from 'react-hook-form';
import { toast } from 'react-toastify';
import { REGISTER_CONSENT_LIST } from '@/constants/constants';
import { CheckMarkSVG } from '@/icons/svg';
import StatusButton from '@/components/Button/StatusButton';
import { Button } from '@/components/Button';
import { IMarketingConsent, IRegisterConsents } from '@/types/auth';

interface IUserConsentForm {
Expand Down Expand Up @@ -233,16 +233,17 @@ const UserConsentForm = ({
</ul>

<div className="mt-auto flex gap-3">
<StatusButton disabled={false} onClick={handlePrev}>
<Button color="secondary" disabled={false} onClick={handlePrev}>
이전
</StatusButton>
<StatusButton
</Button>
<Button
color="secondary"
disabled={!consents.termsOfService}
type="submit"
onClick={handleSubmit(onSubmit)}
>
다음
</StatusButton>
</Button>
</div>
</section>
);
Expand Down
25 changes: 16 additions & 9 deletions src/app/(auth)/_components/Register/Steps/UserSetup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useForm, FieldErrors } from 'react-hook-form';
import { toast } from 'react-toastify';
import { KaKaoTalkSVG, NaverSVG, GoogleSVG, CheckMarkSVG } from '@/icons/svg';
import { checkUserNickname } from '@/lib/apis/userApi';
import StatusButton from '@/components/Button/StatusButton';
import { Button } from '@/components/Button';
import { SignInResponse } from '@/types/auth';
import { IRegisterForm } from '@/types/form';
import { FetchError } from '@/types/types';
Expand Down Expand Up @@ -198,12 +198,13 @@ const UserSetup = ({
</div>

<div className="w-full max-w-[6rem]">
<StatusButton
<Button
color="secondary"
disabled={!nickname || nickname === validatedNickname}
onClick={validateNickname}
>
중복확인
</StatusButton>
</Button>
</div>
</div>
</li>
Expand Down Expand Up @@ -240,7 +241,8 @@ const UserSetup = ({
</div>

<div className="w-full max-w-[6rem]">
<StatusButton
<Button
color="secondary"
disabled={
!phoneNumber ||
phoneNumber === validatedPhoneNumber ||
Expand All @@ -249,7 +251,7 @@ const UserSetup = ({
onClick={validatePhoneNumber}
>
번호인증
</StatusButton>
</Button>
</div>
</div>
</div>
Expand All @@ -264,23 +266,28 @@ const UserSetup = ({
/>

<div className="w-full max-w-[6rem]">
<StatusButton
<Button
color="secondary"
disabled={
!numberValidation || validatedPhoneNumber === phoneNumber
}
onClick={handleNumberValidation}
>
인증하기
</StatusButton>
</Button>
</div>
</div>
)}
</li>
</ul>
<div className="mt-auto flex justify-end">
<StatusButton disabled={!(name && validatedNickname)} type="submit">
<Button
color="secondary"
disabled={!(name && validatedNickname)}
type="submit"
>
다음
</StatusButton>
</Button>
</div>
</form>
</section>
Expand Down
2 changes: 1 addition & 1 deletion src/app/(auth)/_components/Register/UploadProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { toast } from 'react-toastify';
import { AddImageSVG, TrashcanSVG } from '@/../public/icons/svg';
import { postProfileImage } from '@/lib/apis/userApi';
import { useUserStore } from '@/store';
import Button from '@/components/Button/Button';
import { Button } from '@/components/Button';

const UploadProfile = () => {
const [imgSrc, setImgSrc] = useState<string | null>(null);
Expand Down
2 changes: 1 addition & 1 deletion src/app/(auth)/_components/Register/Welcome.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client';
import { useRouter } from 'next/navigation';
import { AuthWelcomeSVG, DoubleRightSVG } from '@/icons/svg';
import Button from '@/components/Button/Button';
import { Button } from '@/components/Button';

const Welcome = ({ nickname }: { nickname: string }) => {
const router = useRouter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,20 @@ if (!END_POINT) {

export const GET = async (request: NextRequest) => {
const searchParams = request.nextUrl.searchParams;
const id = searchParams.get('id');
const order = searchParams.get('orderBy');

const token = request.cookies.get('userAccessToken')?.value;

const {
lectureId,
take,
currentPage,
targetPage,
firstItemId,
lastItemId,
orderBy,
} = Object.fromEntries(searchParams);

const query = `take=${take}&currentPage=${currentPage}&targetPage=${targetPage}&firstItemId=${firstItemId}&lastItemId=${lastItemId}&orderBy=${orderBy}`;

const headers: Record<string, string> = token
? {
Authorization: `Bearer ${token}`,
Expand All @@ -24,7 +33,7 @@ export const GET = async (request: NextRequest) => {
};

const serverResponse = await fetch(
END_POINT + `/lecture-reviews/lectures/${id}?orderBy=${order}`,
END_POINT + `/lecture-reviews/lectures/${lectureId}?${query}`,
{
headers,
},
Expand Down
10 changes: 4 additions & 6 deletions src/app/api/post/review/instructor/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,19 @@ if (!END_POINT) {

export const GET = async (request: NextRequest) => {
const searchParams = request.nextUrl.searchParams;
const lecturerId = searchParams.get('id');
const order = searchParams.get('orderBy');

const token = request.cookies.get('userAccessToken')?.value;

const {
displayCount,
lecturerId,
take,
currentPage,
targetPage,
firstItemId,
lastItemId,
lecturerReviewType,
orderBy,
} = Object.fromEntries(searchParams);

const query = `take=${displayCount}&currentPage=${currentPage}&targetPage=${targetPage}&firstItemId=${firstItemId}&lastItemId=${lastItemId}&lecturerReviewType=${lecturerReviewType}`;
const query = `take=${take}&currentPage=${currentPage}&targetPage=${targetPage}&firstItemId=${firstItemId}&lastItemId=${lastItemId}&orderBy=${orderBy}`;

const headers: Record<string, string> = token
? {
Expand Down
116 changes: 6 additions & 110 deletions src/app/class/@modal/(...)receipt/page.tsx
Original file line number Diff line number Diff line change
@@ -1,118 +1,14 @@
import { Fragment } from 'react';
import { getReceipt } from '@/lib/apis/serverApis/paymentsApis';
import { formatFullDateTime } from '@/utils/dateTimeUtils';
import Modal from '@/components/Modal/ReceiptModal';
import { ISSUER_CODE } from '@/constants/constants';
import Receipt from '@/components/uis/Receipt';

const ReceiptModalPage = async ({
searchParams,
}: {
searchParams: { [key: string]: string };
}) => {
const { orderId } = searchParams;
const receiptData = await getReceipt(orderId);
if (receiptData instanceof Error) return;

const {
orderName,
updatedAt,
originalPrice,
finalPrice,
cardPaymentInfo,
paymentCouponUsage,
} = receiptData;

const issuer = cardPaymentInfo ? ISSUER_CODE[cardPaymentInfo.issuerCode] : '';

// 무통장, 패스권일 때 로직 추가 예정
const paymentDetails = [
{
type: '클래스명',
content: orderName,
},
{
type: '승인일시',
content: formatFullDateTime(updatedAt),
},
{
type: '승인번호',
content: cardPaymentInfo?.approveNo,
},
{
type: '결제수단',
content: `${issuer} (${cardPaymentInfo?.number.slice(-4)})`,
},
{
type: '결제구분',
content:
cardPaymentInfo?.installmentPlanMonths === 0
? '일시불'
: cardPaymentInfo?.installmentPlanMonths,
},

{
type: '클래스 금액',
content: `${originalPrice.toLocaleString()} 원`,
},
];

// 쿠폰 관련 추후 수정 필요
const couponDetails = paymentCouponUsage
? {
type: '적용 쿠폰',
content: (
<>
- {paymentCouponUsage?.couponDiscountPrice?.toLocaleString()}{' '}
<br />({paymentCouponUsage.couponTitle})
{paymentCouponUsage.stackableCouponDiscountPrice &&
paymentCouponUsage.stackableCouponTitle ? (
<>
<br />-
{paymentCouponUsage.stackableCouponDiscountPrice.toLocaleString()}
<br />({paymentCouponUsage.stackableCouponTitle})
</>
) : null}
</>
),
}
: {};

const receiptDetails = [...paymentDetails, couponDetails];

return (
<Modal>
<div className="relative mx-auto box-border flex flex-col items-center pb-[3.5rem] leading-normal">
<h1 className="mb-1 text-lg font-semibold">Connection</h1>
<p className="text-sm font-semibold text-gray-300">{orderId}</p>
<hr className="my-4 w-full border-main-color" />

<ul className="mt-4 grid w-full grid-cols-[min-content_minmax(auto,_1fr)] items-baseline gap-y-2 text-sm font-normal">
{receiptDetails.map((detail, index) => (
<Fragment key={index}>
<li className="flex w-fit whitespace-nowrap text-gray-300">
{detail.type}
</li>
<li className="break-words text-right">{detail.content}</li>
{index === 0 || index === 4 ? (
<hr className="col-span-2 my-2 border-dashed border-gray-500" />
) : null}
</Fragment>
))}
</ul>
<div className="mb-6 mt-6 flex w-full items-center justify-between ">
<p className="whitespace-nowrap text-lg font-semibold">총 결제금액</p>
<p className="whitespace-pre-wrap break-words text-right text-2xl font-semibold text-main-color">
{finalPrice.toLocaleString()}
</p>
</div>

{/* 결제 취소 API 연동 필요 */}
<button className="h-8 w-full rounded-md border border-solid border-gray-700 text-sm font-medium">
결제취소
</button>
</div>
</Modal>
);
};
}) => (
<Modal>
<Receipt searchParams={searchParams} />
</Modal>
);

export default ReceiptModalPage;
Loading

0 comments on commit fe92b75

Please sign in to comment.