feat(onboarding/phase-5): wire real forms into the setup wizard

Replaces the Phase 2 StepPlaceholder with six dedicated wizard step
components, each wrapping the corresponding Phase 3/4 form. The parent
setup-wizard.tsx is now a thin dispatcher that owns shell state +
markSetupStepComplete wiring; each step owns its own data load, form
state, validation, and save action.

- src/components/setup/wizard-step-types.ts — shared
  WizardStepComponentProps shape
- src/components/setup/wizard-step-identity.tsx — minimal brand form
  (hospital name + logo URL) hitting /api/config/theme, links out to
  /branding for full customisation
- src/components/setup/wizard-step-clinics.tsx — ClinicForm + createClinic
  mutation, always presents an empty "add new" form
- src/components/setup/wizard-step-doctors.tsx — DoctorForm with clinic
  dropdown, blocks with an inline warning when no clinics exist yet
- src/components/setup/wizard-step-team.tsx — InviteMemberForm with real
  roles fetched from getRoles, sends invitations via sendInvitations
- src/components/setup/wizard-step-telephony.tsx — loads masked config
  from /api/config/telephony, validates required Ozonetel fields on save
- src/components/setup/wizard-step-ai.tsx — loads AI config, clamps
  temperature 0..2, doesn't auto-advance (last step, admin taps Finish)
- src/pages/setup-wizard.tsx — dispatches to the right step component
  based on activeStep, passes a WizardStepComponentProps bundle

Each step calls onComplete(step) after a successful save, which updates
the shared SetupState so the left-nav badges reflect the new status
immediately.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-07 07:54:35 +05:30
parent a7b2fd7fbe
commit a287a97fe4
8 changed files with 646 additions and 54 deletions

View File

@@ -0,0 +1,100 @@
import { useEffect, useState } from 'react';
import { WizardStep } from './wizard-step';
import {
InviteMemberForm,
type InviteMemberFormValues,
type RoleOption,
} from '@/components/forms/invite-member-form';
import { apiClient } from '@/lib/api-client';
import { notify } from '@/lib/toast';
import type { WizardStepComponentProps } from './wizard-step-types';
// Team step — fetch roles from the platform and present the invite form.
// The admin types one or more emails and picks a role. sendInvitations
// fires, the backend emails them, and the wizard advances on success.
//
// Role assignment itself happens AFTER the invitee accepts (since we only
// have a workspaceMemberId once they've joined the workspace). For now we
// just send the invitations — the admin can finalise role assignments
// from /settings/team once everyone has accepted.
export const WizardStepTeam = (props: WizardStepComponentProps) => {
const [values, setValues] = useState<InviteMemberFormValues>({ emails: [], roleId: '' });
const [roles, setRoles] = useState<RoleOption[]>([]);
const [saving, setSaving] = useState(false);
useEffect(() => {
apiClient
.graphql<{
getRoles: {
id: string;
label: string;
description: string | null;
canBeAssignedToUsers: boolean;
}[];
}>(`{ getRoles { id label description canBeAssignedToUsers } }`, undefined, { silent: true })
.then((data) =>
setRoles(
data.getRoles
.filter((r) => r.canBeAssignedToUsers)
.map((r) => ({
id: r.id,
label: r.label,
supportingText: r.description ?? undefined,
})),
),
)
.catch(() => setRoles([]));
}, []);
const handleSave = async () => {
if (values.emails.length === 0) {
notify.error('Add at least one email');
return;
}
setSaving(true);
try {
await apiClient.graphql(
`mutation SendInvitations($emails: [String!]!) {
sendInvitations(emails: $emails) { success errors }
}`,
{ emails: values.emails },
);
notify.success(
'Invitations sent',
`${values.emails.length} invitation${values.emails.length === 1 ? '' : 's'} sent.`,
);
await props.onComplete('team');
setValues({ emails: [], roleId: '' });
props.onAdvance();
} catch (err) {
console.error('[wizard/team] invite failed', err);
} finally {
setSaving(false);
}
};
return (
<WizardStep
step="team"
isCompleted={props.isCompleted}
isLast={props.isLast}
onPrev={props.onPrev}
onNext={props.onNext}
onMarkComplete={handleSave}
onFinish={props.onFinish}
saving={saving}
>
{props.isCompleted && (
<div className="mb-5 rounded-lg border border-secondary bg-secondary p-4 text-xs text-tertiary">
Invitations already sent. Add more emails below to invite additional members, or click{' '}
<b>Next</b> to continue.
</div>
)}
<InviteMemberForm value={values} onChange={setValues} roles={roles} />
<p className="mt-4 text-xs text-tertiary">
Invited members receive an email with a link to set their password. Fine-tune role assignments
from the Team page after they join.
</p>
</WizardStep>
);
};