feat: add country selection during onboarding and implement payment management features
- Introduced CountryStep component for selecting the country during onboarding, affecting payment currency. - Updated FirstGroupStep to include country information. - Enhanced PaymentsProvider to manage payment states and renewals. - Created PaymentRow component for displaying individual payment details. - Implemented PaymentsView for listing and filtering payments by group and status. - Added API endpoints for fetching and creating payments, including batch processing. - Defined payment schemas for validation and data handling. - Updated GroupHeader and GroupDetailView to include charging functionality for group members.
This commit is contained in:
82
apps/web/src/features/onboarding/CountryStep.tsx
Normal file
82
apps/web/src/features/onboarding/CountryStep.tsx
Normal file
@@ -0,0 +1,82 @@
|
||||
import type { CountryCode } from '@gruperly/shared'
|
||||
import { COUNTRY_CURRENCY, COUNTRY_LABELS, DEFAULT_COUNTRY } from '@gruperly/shared'
|
||||
import { ArrowLeft, ArrowRight } from 'lucide-react'
|
||||
import { useState } from 'react'
|
||||
import { Button } from '../../components/ui'
|
||||
import { cn } from '../../lib/utils'
|
||||
|
||||
export const COUNTRY_OPTIONS: readonly CountryCode[] = [
|
||||
'AR',
|
||||
'BR',
|
||||
'CL',
|
||||
'CO',
|
||||
'MX',
|
||||
'PE',
|
||||
'UY',
|
||||
]
|
||||
|
||||
type CountryStepProps = {
|
||||
onNext: () => void
|
||||
onBack: () => void
|
||||
}
|
||||
|
||||
/**
|
||||
* Paso "País" del onboarding.
|
||||
*
|
||||
* El país del profesor define la moneda con la que se generan los links de
|
||||
* cobro, así que se pregunta al empezar. Por default Argentina (la moneda por
|
||||
* default es ARS); se cambia después desde Ajustes.
|
||||
*/
|
||||
export function CountryStep({ onNext, onBack }: CountryStepProps) {
|
||||
const [country, setCountry] = useState<CountryCode>(DEFAULT_COUNTRY)
|
||||
|
||||
return (
|
||||
<section className="space-y-5">
|
||||
<header className="space-y-1">
|
||||
<h2 className="text-2xl font-bold text-primary">¿En qué país vas a cobrar?</h2>
|
||||
<p className="text-sm text-foreground/60">
|
||||
Tus links se generan en la moneda de ese país.
|
||||
</p>
|
||||
</header>
|
||||
|
||||
<div role="radiogroup" aria-label="País" className="space-y-2">
|
||||
{COUNTRY_OPTIONS.map((code) => {
|
||||
const isSelected = code === country
|
||||
return (
|
||||
<label
|
||||
key={code}
|
||||
className={cn(
|
||||
'flex cursor-pointer items-center gap-3 rounded-xl border border-border bg-surface px-4 py-3 transition-colors',
|
||||
isSelected && 'border-accent bg-accent-soft ring-2 ring-accent/20',
|
||||
)}
|
||||
>
|
||||
<input
|
||||
type="radio"
|
||||
name="country"
|
||||
value={code}
|
||||
checked={isSelected}
|
||||
onChange={() => setCountry(code)}
|
||||
className="size-4 accent-accent"
|
||||
/>
|
||||
<span className="flex-1 text-sm font-medium text-primary">
|
||||
{COUNTRY_LABELS[code]}
|
||||
</span>
|
||||
<span className="text-sm text-foreground/50">{COUNTRY_CURRENCY[code]}</span>
|
||||
</label>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-3">
|
||||
<Button variant="outline" onClick={onBack} className="hidden lg:inline-flex">
|
||||
<ArrowLeft className="size-4" />
|
||||
Volver
|
||||
</Button>
|
||||
<Button variant="primary" className="flex-1 lg:flex-none" onClick={() => onNext()}>
|
||||
Continuar
|
||||
<ArrowRight className="size-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import type { CreateFirstGroup, OnboardingGroupDto } from '@gruperly/shared'
|
||||
import { useMutation } from '@tanstack/react-query'
|
||||
import { createFirstGroup } from '../../lib/api'
|
||||
import { GroupForm } from '../groups/GroupForm'
|
||||
import { useOnboarding } from './OnboardingProvider'
|
||||
|
||||
type FirstGroupStepProps = {
|
||||
onBack: () => void
|
||||
@@ -9,6 +10,7 @@ type FirstGroupStepProps = {
|
||||
}
|
||||
|
||||
export function FirstGroupStep({ onBack, onCompleted }: FirstGroupStepProps) {
|
||||
const { country } = useOnboarding()
|
||||
const create = useMutation({
|
||||
mutationFn: (values: CreateFirstGroup) => createFirstGroup(values),
|
||||
onSuccess: (result) => onCompleted(result.group),
|
||||
@@ -19,6 +21,7 @@ export function FirstGroupStep({ onBack, onCompleted }: FirstGroupStepProps) {
|
||||
heading="Tu primer grupo"
|
||||
description="Definí los datos de la clase que vas a cobrar. Después siempre podés editarlos."
|
||||
submitLabel="Crear grupo"
|
||||
country={country}
|
||||
isSubmitting={create.isPending}
|
||||
errorMessage={
|
||||
create.isError ? 'No pudimos crear el grupo. Revisá los datos e intentá de nuevo.' : null
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { OnboardingGroupDto, OnboardingStatusDto } from '@gruperly/shared'
|
||||
import type { CountryCode, OnboardingGroupDto, OnboardingStatusDto } from '@gruperly/shared'
|
||||
import { DEFAULT_COUNTRY } from '@gruperly/shared'
|
||||
import type { UseQueryResult } from '@tanstack/react-query'
|
||||
import { useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { useNavigate, useSearch } from '@tanstack/react-router'
|
||||
@@ -10,12 +11,15 @@ import type { MpCallbackFeedback } from '../mp'
|
||||
import { mpStatusQueryKey, readMpCallbackFeedback } from '../mp'
|
||||
|
||||
const WELCOME_STEP = 0
|
||||
const PAYMENT_STEP = 1
|
||||
const FIRST_GROUP_STEP = 2
|
||||
const PAYMENT_STEP = 2
|
||||
const FIRST_GROUP_STEP = 3
|
||||
|
||||
type OnboardingContextValue = {
|
||||
step: number
|
||||
setStep: (step: number) => void
|
||||
/** El país del profesor; define la moneda de los links de cobro. */
|
||||
country: CountryCode
|
||||
setCountry: (country: CountryCode) => void
|
||||
/** Lo que volvió de Mercado Pago en `?mp=`, ya traducido a feedback. */
|
||||
mpFeedback: MpCallbackFeedback | null
|
||||
createdGroup: OnboardingGroupDto | null
|
||||
@@ -31,6 +35,7 @@ export function OnboardingProvider({ children }: { children: ReactNode }) {
|
||||
const queryClient = useQueryClient()
|
||||
const search = useSearch({ from: '/onboarding' })
|
||||
const [step, setStep] = useState(WELCOME_STEP)
|
||||
const [country, setCountry] = useState<CountryCode>(DEFAULT_COUNTRY)
|
||||
const [mpFeedback, setMpFeedback] = useState<MpCallbackFeedback | null>(null)
|
||||
const [createdGroup, setCreatedGroup] = useState<OnboardingGroupDto | null>(null)
|
||||
|
||||
@@ -79,6 +84,8 @@ export function OnboardingProvider({ children }: { children: ReactNode }) {
|
||||
value={{
|
||||
step,
|
||||
setStep,
|
||||
country,
|
||||
setCountry,
|
||||
mpFeedback,
|
||||
createdGroup,
|
||||
setCreatedGroup,
|
||||
|
||||
@@ -5,6 +5,7 @@ import { Logo, LogoIcon } from '../../components/brand'
|
||||
import { Button } from '../../components/ui'
|
||||
import { useAuth } from '../../context/AuthProvider'
|
||||
import { ConfirmationStep } from './ConfirmationStep'
|
||||
import { CountryStep } from './CountryStep'
|
||||
import { FirstGroupStep } from './FirstGroupStep'
|
||||
import { useOnboarding } from './OnboardingProvider'
|
||||
import { PaymentStep } from './PaymentStep'
|
||||
@@ -13,6 +14,7 @@ import { WelcomeStep } from './WelcomeStep'
|
||||
|
||||
const STEPS = [
|
||||
{ label: 'Bienvenida' },
|
||||
{ label: 'País' },
|
||||
{ label: 'Cobros' },
|
||||
{ label: 'Tu grupo' },
|
||||
{ label: 'Listo' },
|
||||
@@ -81,18 +83,21 @@ export function OnboardingView() {
|
||||
<div key={step} className="mt-8 animate-step-enter">
|
||||
{step === 0 ? <WelcomeStep name={firstName} onNext={() => setStep(1)} /> : null}
|
||||
{step === 1 ? (
|
||||
<PaymentStep feedback={mpFeedback} onNext={() => setStep(2)} onBack={() => setStep(0)} />
|
||||
<CountryStep onNext={() => setStep(2)} onBack={() => setStep(0)} />
|
||||
) : null}
|
||||
{step === 2 ? (
|
||||
<PaymentStep feedback={mpFeedback} onNext={() => setStep(3)} onBack={() => setStep(1)} />
|
||||
) : null}
|
||||
{step === 3 ? (
|
||||
<FirstGroupStep
|
||||
onBack={() => setStep(1)}
|
||||
onBack={() => setStep(2)}
|
||||
onCompleted={(group) => {
|
||||
setCreatedGroup(group)
|
||||
setStep(3)
|
||||
setStep(4)
|
||||
}}
|
||||
/>
|
||||
) : null}
|
||||
{step === 3 && createdGroup ? <ConfirmationStep group={createdGroup} /> : null}
|
||||
{step === 4 && createdGroup ? <ConfirmationStep group={createdGroup} /> : null}
|
||||
</div>
|
||||
</main>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user