This commit is contained in:
2025-12-25 23:23:34 -03:00
parent dbfa82ce72
commit 4ebbc048f1
4 changed files with 61 additions and 19 deletions

View File

@@ -1,4 +1,3 @@
import { useWizard } from '@/components/wizard'
import { Currency } from '@repo/ui/components/currency'
import { Button } from '@repo/ui/components/ui/button'
import { Separator } from '@repo/ui/components/ui/separator'
@@ -12,13 +11,29 @@ import {
TableRow
} from '@repo/ui/components/ui/table'
import { useWizard } from '@/components/wizard'
import { applyDiscount } from './discount'
type ReviewProps = {
state: any
}
export function Review({ state }: ReviewProps) {
const wizard = useWizard()
// console.log(state)
const { coupon, items } = state.cart || { items: [], coupon: {} }
const subtotal =
items?.reduce(
(acc, { course, quantity }) =>
acc +
(course?.unit_price || 0) *
(Number.isFinite(quantity) && quantity > 0 ? quantity : 1),
0
) || 0
const discount = coupon
? applyDiscount(subtotal, coupon.amount, coupon.type) * -1
: 0
const total = subtotal > 0 ? subtotal + discount : 0
return (
<>
@@ -32,7 +47,7 @@ export function Review({ state }: ReviewProps) {
</TableRow>
</TableHeader>
<TableBody>
{state?.cart?.items?.map(({ course, quantity }, index) => {
{items?.map(({ course, quantity }, index) => {
return (
<TableRow key={index}>
<TableCell>{course.name}</TableCell>
@@ -52,26 +67,32 @@ export function Review({ state }: ReviewProps) {
<TableCell className="text-right" colSpan={3}>
Subtotal
</TableCell>
<TableCell>..</TableCell>
<TableCell>
<Currency>{subtotal}</Currency>
</TableCell>
</TableRow>
<TableRow className="pointer-events-none">
<TableCell className="text-right" colSpan={3}>
Descontos
</TableCell>
<TableCell>..</TableCell>
<TableCell>
<Currency>{discount}</Currency>
</TableCell>
</TableRow>
<TableRow className="pointer-events-none">
<TableCell className="text-right" colSpan={3}>
Total
</TableCell>
<TableCell>..</TableCell>
<TableCell>
<Currency>{total}</Currency>
</TableCell>
</TableRow>
</TableFooter>
</Table>
<Separator />
<div className="flex justify-end gap-4 *:cursor-pointer">
<div className="flex justify-between gap-4 *:cursor-pointer">
<Button
type="button"
variant="link"
@@ -80,7 +101,9 @@ export function Review({ state }: ReviewProps) {
>
Voltar
</Button>
<Button type="submit">Confirmar</Button>
<Button type="submit">
Pagar <Currency>{total}</Currency>
</Button>
</div>
</>
)