From 8b81d5c24505f11e7e5b93c0555e80fc9581e1c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Rafael=20Siqueira?= Date: Sat, 27 Dec 2025 20:48:04 -0300 Subject: [PATCH] add dialog --- .../_.$orgid.enrollments.buy/payment.tsx | 251 ++++++++-------- .../_.$orgid.enrollments.buy/review.tsx | 267 ++++++++++++++++-- 2 files changed, 357 insertions(+), 161 deletions(-) diff --git a/apps/admin.saladeaula.digital/app/routes/_.$orgid.enrollments.buy/payment.tsx b/apps/admin.saladeaula.digital/app/routes/_.$orgid.enrollments.buy/payment.tsx index f125273..70a0ad6 100644 --- a/apps/admin.saladeaula.digital/app/routes/_.$orgid.enrollments.buy/payment.tsx +++ b/apps/admin.saladeaula.digital/app/routes/_.$orgid.enrollments.buy/payment.tsx @@ -176,160 +176,151 @@ export function CreditCard({ control }: { control: Control }) {
- - {/* Credir card number */} + {/* Credir card number */} + ( + + Número do cartão + { + onChange(value) + }} + {...field} + /> + + {fieldState.invalid && ( + + )} + + )} + /> + {/* Holder name */} + ( + + Nome do titular + + {fieldState.invalid && ( + + )} + + )} + /> + +
( + name="credit_card.exp_month" + defaultValue="" + render={({ field, fieldState }) => ( - - Número do cartão - - Mês + { - onChange(value) - }} - {...field} - /> + > + + Selecione + - {fieldState.invalid && ( - - )} + {Array.from({ length: 12 }, (_, i) => { + const v = String(i + 1).padStart(2, '0') + return ( + + {v} + + ) + })} + )} /> - {/* Holder name */} + ( + + Ano + + + Selecione + + + {years.map((year) => ( + + {year} + + ))} + + + )} + /> + + ( - Nome do titular + CVC + + + + + +

+ O CVC é o código de segurança do cartão + de crédito. +

+ +

+ Ele fica no verso do cartão e geralmente possui{' '} + 3 dígitos (ou 4 dígitos na + frente, no caso do American Express). +

+
+
- {fieldState.invalid && ( - - )}
)} /> - -
- ( - - Mês - - - Selecione - - - {Array.from({ length: 12 }, (_, i) => { - const v = String(i + 1).padStart(2, '0') - return ( - - {v} - - ) - })} - - - )} - /> - - ( - - Ano - - - Selecione - - - {years.map((year) => ( - - {year} - - ))} - - - )} - /> - - ( - - - CVC - - - - - -

- O CVC é o código de segurança do cartão - de crédito. -

- -

- Ele fica no verso do cartão e geralmente possui{' '} - 3 dígitos (ou 4 dígitos na - frente, no caso do American Express). -

-
-
-
- -
- )} - /> -
- +
diff --git a/apps/admin.saladeaula.digital/app/routes/_.$orgid.enrollments.buy/review.tsx b/apps/admin.saladeaula.digital/app/routes/_.$orgid.enrollments.buy/review.tsx index 7b1c1a6..ae90395 100644 --- a/apps/admin.saladeaula.digital/app/routes/_.$orgid.enrollments.buy/review.tsx +++ b/apps/admin.saladeaula.digital/app/routes/_.$orgid.enrollments.buy/review.tsx @@ -1,6 +1,9 @@ import { useToggle } from 'ahooks' -import { PencilIcon } from 'lucide-react' -import { useForm } from 'react-hook-form' +import { PatternFormat } from 'react-number-format' +import { ExternalLinkIcon, PencilIcon, SearchIcon } from 'lucide-react' +import { Controller, useForm } from 'react-hook-form' +import { zodResolver } from '@hookform/resolvers/zod' +import { z } from 'zod' import valid from 'card-validator' import { Currency } from '@repo/ui/components/currency' @@ -39,6 +42,21 @@ import { useWizard } from '@/components/wizard' import { type WizardState } from './route' import { applyDiscount } from './discount' import { paymentMethods } from '@repo/ui/routes/orders/data' +import { + Field, + FieldDescription, + FieldError, + FieldGroup, + FieldLabel, + FieldSet +} from '@repo/ui/components/ui/field' +import { Input } from '@repo/ui/components/ui/input' +import { + InputGroup, + InputGroupAddon, + InputGroupButton, + InputGroupInput +} from '@repo/ui/components/ui/input-group' type ReviewProps = { state: WizardState @@ -64,7 +82,7 @@ export function Review({ state, onSubmit }: ReviewProps) { return ( <> -
+
{ @@ -150,9 +168,12 @@ export function Review({ state, onSubmit }: ReviewProps) { ) } -export function Address({ payment_method, credit_card }: WizardState) { +export function Address({ + total, + payment_method, + credit_card +}: WizardState & { total: number }) { const numberValidation = valid.number(credit_card?.number) - // console.log(numberValidation) return ( @@ -170,7 +191,7 @@ export function Address({ payment_method, credit_card }: WizardState) { - + @@ -178,14 +199,20 @@ export function Address({ payment_method, credit_card }: WizardState) { Forma de pagamento - {payment_method ? paymentMethods[payment_method] : payment_method} {credit_card ? ( <> -
- {numberValidation.card?.niceType} ****{' '} + {numberValidation.card?.niceType} (Crédito) ****{' '} {credit_card.number.slice(-4)} +
+ 1x {total} - ) : null} + ) : ( + <> + {payment_method + ? paymentMethods[payment_method] + : payment_method} + + )}
@@ -193,27 +220,41 @@ export function Address({ payment_method, credit_card }: WizardState) { ) } -export function DialogDemo() { - const form = useForm() - const { handleSubmit } = form +const formSchema = z.object({ + postcode: z.string().min(1, 'Digite um CEP'), + address1: z.string().min(1, 'Digite um endereço'), + address2: z.string().optional(), + neighborhood: z.string().min(1, 'Digite o bairro'), + city: z.string().min(1, 'Digite a cidade'), + state: z.string().min(1, 'Digite o estado') +}) - const onSubmit = async () => {} +type Schema = z.infer + +export function AddressDialog() { + const { handleSubmit, control } = useForm({ + resolver: zodResolver(formSchema) + }) + + const onSubmit = async (data: Schema) => { + console.log(data) + } return ( - - - - - - + + + + + + Editar endereço @@ -221,6 +262,170 @@ export function DialogDemo() { + +
+ ( + + CEP + + {/**/} + + { + onChange(value) + }} + {...field} + /> + + + + + + + + + Não sei o CEP + + + + {fieldState.invalid && ( + + )} + + )} + /> + + ( + + Endereço + + + {fieldState.invalid && ( + + )} + + )} + /> + + ( + + + Complemento{' '} + (opcional) + + + + {fieldState.invalid && ( + + )} + + )} + /> +
+ +
+ {/* Neighborhood */} + ( + + Bairro + + + {fieldState.invalid && ( + + )} + + )} + /> + {/* City */} + ( + + Cidade + + + {fieldState.invalid && ( + + )} + + )} + /> + {/* State */} + ( + + Estado + + + {fieldState.invalid && ( + + )} + + )} + /> +
+
+ -
-
- + +
+
) }