mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-20 09:53:06 +00:00
Ações de ajuste (votos, tendência, atualização, liderança) agora retornam à origem ao salvar (toast + from allowlist B110 / Início), sem avançar sozinhas para outro wizard. Removidos fila de encadeamento (wizardActionChain.ts), param entry, skip/Pular (chrome mobile sempre X) e prefill de nota sem produtor. Liderança: botão pós-save 'Continuar' → 'Concluir' (origem). Sem migration.
86 lines
2.1 KiB
TypeScript
86 lines
2.1 KiB
TypeScript
'use client'
|
|
|
|
import {
|
|
createContext,
|
|
useContext,
|
|
useLayoutEffect,
|
|
useMemo,
|
|
useState,
|
|
type Dispatch,
|
|
type ReactNode,
|
|
type SetStateAction,
|
|
} from 'react'
|
|
|
|
export type CampaignWizardChromeState = {
|
|
flowTitle: string
|
|
municipalityLabel?: string
|
|
stepKind: 'entry' | 'continue'
|
|
previousHref?: string
|
|
dismissHref: string
|
|
}
|
|
|
|
type CampaignWizardChromeContextValue = {
|
|
chrome: CampaignWizardChromeState | null
|
|
setChrome: Dispatch<SetStateAction<CampaignWizardChromeState | null>>
|
|
}
|
|
|
|
const CampaignWizardChromeContext = createContext<CampaignWizardChromeContextValue | null>(null)
|
|
|
|
export const CampaignWizardChromeProvider = ({ children }: { children: ReactNode }) => {
|
|
const [chrome, setChrome] = useState<CampaignWizardChromeState | null>(null)
|
|
const value = useMemo(() => ({ chrome, setChrome }), [chrome])
|
|
|
|
return (
|
|
<CampaignWizardChromeContext.Provider value={value}>
|
|
{children}
|
|
</CampaignWizardChromeContext.Provider>
|
|
)
|
|
}
|
|
|
|
const useCampaignWizardChromeContext = (): CampaignWizardChromeContextValue => {
|
|
const value = useContext(CampaignWizardChromeContext)
|
|
if (!value) {
|
|
throw new Error('CampaignWizardChromeProvider is required')
|
|
}
|
|
return value
|
|
}
|
|
|
|
export const useCampaignWizardChrome = (): CampaignWizardChromeState | null =>
|
|
useCampaignWizardChromeContext().chrome
|
|
|
|
type CampaignWizardChromeInput = {
|
|
flowTitle: string
|
|
isEntryStep: boolean
|
|
previousHref: string
|
|
dismissHref: string
|
|
municipalityLabel?: string
|
|
}
|
|
|
|
export const toCampaignWizardChromeState = ({
|
|
flowTitle,
|
|
isEntryStep,
|
|
previousHref,
|
|
dismissHref,
|
|
municipalityLabel,
|
|
}: CampaignWizardChromeInput): CampaignWizardChromeState => ({
|
|
flowTitle,
|
|
municipalityLabel,
|
|
stepKind: isEntryStep ? 'entry' : 'continue',
|
|
previousHref: isEntryStep ? undefined : previousHref,
|
|
dismissHref,
|
|
})
|
|
|
|
export const useSetCampaignWizardChrome = (state: CampaignWizardChromeState | null): void => {
|
|
const { setChrome } = useCampaignWizardChromeContext()
|
|
|
|
useLayoutEffect(() => {
|
|
setChrome(state)
|
|
}, [setChrome, state])
|
|
|
|
useLayoutEffect(
|
|
() => () => {
|
|
setChrome(null)
|
|
},
|
|
[setChrome],
|
|
)
|
|
}
|