Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions jobdri/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"preinstall": "npx only-allow pnpm"
},
"dependencies": {
"@tosspayments/tosspayments-sdk": "^2.7.0",
"clsx": "^2.1.1",
"next": "16.2.4",
"react": "19.2.4",
Expand Down
44 changes: 8 additions & 36 deletions jobdri/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 51 additions & 4 deletions jobdri/src/app/credit/page.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,60 @@
"use client";

import { useEffect, useState } from "react";
import { useSearchParams } from "next/navigation";
import { CreditCard } from "@/components/common/cards";
import Useage from "@/components/credit/Useage";
import Useage from "@/components/common/credit/Useage";
import {
fetchCreditPlans,
confirmPurchase,
type CreditPlan,
} from "@/lib/api/credit";

function calcDiscountRate(plan: CreditPlan, basePricePerUnit: number): string {
const original = basePricePerUnit * plan.creditAmount;
if (original <= plan.price) return "";
const rate = Math.round(((original - plan.price) / original) * 100);
return `${rate}%`;
}

export default function CreditPage() {
const [plans, setPlans] = useState<CreditPlan[]>([]);
const searchParams = useSearchParams();

useEffect(() => {
fetchCreditPlans()
.then(setPlans)
.catch(() => {});
}, []);

useEffect(() => {
const paymentKey = searchParams.get("paymentKey");
const orderId = searchParams.get("orderId");
const amount = searchParams.get("amount");

if (paymentKey && orderId && amount) {
confirmPurchase(paymentKey, orderId, Number(amount)).catch(() => {});
}
}, [searchParams]);

const basePricePerUnit =
plans.find((p) => p.planCode === "ONE_TIME")?.price ?? 2500;

return (
<div className="flex flex-col">
<section className="flex flex-row gap-4 w-full mt-8 mb-16">
<CreditCard creditCount={1} price="2,500" />
<CreditCard creditCount={3} price="2,500" />
<CreditCard creditCount={10} price="2,500" />
{plans.map((plan) => (
<CreditCard
key={plan.planCode}
creditCount={plan.creditAmount}
price={plan.price.toLocaleString()}
planCode={plan.planCode}
discountRate={calcDiscountRate(plan, basePricePerUnit)}
discountLabel={
calcDiscountRate(plan, basePricePerUnit) ? "할인" : ""
}
/>
))}
</section>
<Useage />
</div>
Expand Down
Loading