mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-16 11:33:07 +00:00
Seção 'Receba as novidades da campanha' acima do rodapé: nome + WhatsApp obrigatórios, e-mail/estado/cidade/comentário opcionais, toggle pré-selecionado 'Quero fazer parte do time' gravado como subscription.campaignLevel (time|esporadico). CTA secundário do hero vira o atalho (#novidades, scroll suave). Contact + Subscription em withPayloadTransaction com consentimento novo fail-closed por chave estável 'campanha-novidades' — nada é gravado sem o texto aprovado no admin. Migration 20260819_192605 (state de contact nullable + coluna campaign_level). Impl plan, changelog, int + e2e.
50 lines
1.3 KiB
TypeScript
50 lines
1.3 KiB
TypeScript
import { CitiesByState } from '@/lib/cities'
|
|
import { useEffect, useMemo } from 'react'
|
|
import { useFormContext, useWatch } from 'react-hook-form'
|
|
import { FormCombobox, type ComboboxOption } from './FormCombobox'
|
|
|
|
interface CitySelectProps {
|
|
placeholder?: string
|
|
/** S9 — the campaign home capture makes the city optional (the select
|
|
* stays disabled until a state is picked). Defaults to true so the WhatsApp
|
|
* flow stays as strict as before. */
|
|
required?: boolean
|
|
}
|
|
|
|
export const CitySelect = ({
|
|
placeholder = 'Selecione uma cidade',
|
|
required = true,
|
|
}: CitySelectProps) => {
|
|
const { control, setValue } = useFormContext()
|
|
const state: keyof typeof CitiesByState | undefined = useWatch({
|
|
control,
|
|
name: 'state',
|
|
})
|
|
|
|
const options = useMemo<ComboboxOption[]>(
|
|
() =>
|
|
state
|
|
? CitiesByState[state]
|
|
.map((city) => ({ value: city, label: city }))
|
|
.sort((a, b) => a.label.localeCompare(b.label, 'pt-BR'))
|
|
: [],
|
|
[state],
|
|
)
|
|
|
|
useEffect(() => {
|
|
setValue('city', '')
|
|
}, [state, setValue])
|
|
|
|
return (
|
|
<FormCombobox
|
|
name="city"
|
|
id="city"
|
|
options={options}
|
|
placeholder={placeholder}
|
|
minChars={1}
|
|
disabled={!options.length}
|
|
required={required}
|
|
emptyMessage="Nenhuma cidade encontrada."
|
|
/>
|
|
)
|
|
}
|