feat(dashboard): add onboarding gate forcing company setup before app use
After login/activation, show a full-screen loader while company settings resolve, then force the user onto /settings/company and block navigation to any other route until the company info is filled in. The gate releases once the company record has a name; fails open on API error so a transient failure can never lock the user out. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -4,7 +4,7 @@ import { AlertTriangle, Save } from "lucide-react"
|
||||
import { useEffect } from "react"
|
||||
import { useForm } from "react-hook-form"
|
||||
import { zodResolver } from "@hookform/resolvers/zod"
|
||||
import { useQuery } from "@tanstack/react-query"
|
||||
import { useQuery, useQueryClient } from "@tanstack/react-query"
|
||||
import { toast } from "sonner"
|
||||
|
||||
import { Button } from "@/shared/components/ui/button"
|
||||
@@ -122,6 +122,7 @@ function mapFormToPayload(values: SettingsFormValues) {
|
||||
|
||||
export function SettingsForm() {
|
||||
const api = useAuthApi()
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
const form = useForm<SettingsFormValues>({
|
||||
resolver: zodResolver(settingsFormSchema) as any,
|
||||
@@ -154,6 +155,9 @@ export function SettingsForm() {
|
||||
mutationFn: (values: SettingsFormValues) => api.settings.update(mapFormToPayload(values)),
|
||||
onSuccess: () => {
|
||||
toast.success("Settings saved successfully")
|
||||
// Refresh the settings query so the onboarding gate releases once
|
||||
// the company info has been filled in.
|
||||
queryClient.invalidateQueries({ queryKey: [SETTINGS_ROUTES.INDEX] })
|
||||
},
|
||||
onError: () => {
|
||||
toast.error("Failed to save settings")
|
||||
|
||||
Reference in New Issue
Block a user