feat(onboarding): notifier + storage steps call real actions + findOrCreate on back

This commit is contained in:
Théo LAGACHE
2026-06-18 11:52:12 +02:00
parent 4ea5babba6
commit 49924d9dd9
2 changed files with 73 additions and 6 deletions
@@ -19,13 +19,15 @@ import { notificationProviders } from "@/features/channel/channels-notification-
import { renderChannelForm } from "@/features/channel/channels-helpers";
import { NotificationChannelFormSchema } from "@/features/channel/channel-form.schema";
import { OnboardingChannel } from "@/features/onboarding/onboarding.types";
import { addNotificationChannelAction } from "@/features/channel/notifications/channel.action";
type Phase = { kind: "grid" } | { kind: "configuring"; provider: string };
export const StepNotifier = () => {
const { next, updateContext, state } = useOnboarding();
const [phase, setPhase] = useState<Phase>({ kind: "grid" });
const [channels, setChannels] = useState<OnboardingChannel[]>([]);
const existingNotifiers = (state?.context.flowData.notifiers ?? []) as OnboardingChannel[];
const [channels, setChannels] = useState<OnboardingChannel[]>(existingNotifiers);
const [pending, setPending] = useState(false);
const form = useZodForm({ schema: NotificationChannelFormSchema });
@@ -43,8 +45,40 @@ export const StepNotifier = () => {
const onContinue = async () => {
setPending(true);
await updateContext({ flowData: { ...state?.context.flowData, notifiers: channels } });
await next();
try {
const orgId = (state?.context.flowData.org as any)?.id as string | undefined;
const persistedChannels: OnboardingChannel[] = [];
for (const ch of channels) {
// Skip channels already persisted (have a real UUID from previous continue)
const alreadyPersisted = existingNotifiers.some((n) => n.id === ch.id && n.id.length === 36);
if (alreadyPersisted) {
persistedChannels.push(ch);
continue;
}
const result = await addNotificationChannelAction({
organizationId: orgId,
data: { provider: ch.provider as any, name: ch.name, config: ch.config as any, enabled: true },
});
const inner = result?.data;
if (inner?.success && inner.value) {
persistedChannels.push({
id: inner.value.id,
provider: ch.provider,
label: ch.label,
name: ch.name,
config: ch.config,
});
}
}
await updateContext({
flowData: { ...state?.context.flowData, notifiers: persistedChannels },
});
await next();
} finally {
setPending(false);
}
};
if (phase.kind === "configuring") {
+36 -3
View File
@@ -19,13 +19,15 @@ import { storageProviders } from "@/features/channel/channels-storage-helper";
import { renderChannelForm } from "@/features/channel/channels-helpers";
import { StorageChannelFormSchema } from "@/features/channel/channel-form.schema";
import { OnboardingChannel } from "@/features/onboarding/onboarding.types";
import { addStorageChannelAction } from "@/features/channel/storages/channel.action";
type Phase = { kind: "grid" } | { kind: "configuring"; provider: string };
export const StepStorage = () => {
const { next, updateContext, state } = useOnboarding();
const [phase, setPhase] = useState<Phase>({ kind: "grid" });
const [channels, setChannels] = useState<OnboardingChannel[]>([]);
const existingStorages = (state?.context.flowData.storages ?? []) as OnboardingChannel[];
const [channels, setChannels] = useState<OnboardingChannel[]>(existingStorages);
const [pending, setPending] = useState(false);
const form = useZodForm({ schema: StorageChannelFormSchema });
@@ -42,8 +44,39 @@ export const StepStorage = () => {
const onContinue = async () => {
setPending(true);
await updateContext({ flowData: { ...state?.context.flowData, storages: channels } });
await next();
try {
const orgId = (state?.context.flowData.org as any)?.id as string | undefined;
const persistedChannels: OnboardingChannel[] = [];
for (const ch of channels) {
const alreadyPersisted = existingStorages.some((s) => s.id === ch.id && ch.id.length === 36);
if (alreadyPersisted) {
persistedChannels.push(ch);
continue;
}
const result = await addStorageChannelAction({
organizationId: orgId,
data: { provider: ch.provider as any, name: ch.name, config: ch.config as any, enabled: true },
});
const inner = result?.data;
if (inner?.success && inner.value) {
persistedChannels.push({
id: inner.value.id,
provider: ch.provider,
label: ch.label,
name: ch.name,
config: ch.config,
});
}
}
await updateContext({
flowData: { ...state?.context.flowData, storages: persistedChannels },
});
await next();
} finally {
setPending(false);
}
};
if (phase.kind === "configuring") {