mirror of
https://github.com/R0m1k3/PleinR.git
synced 2026-10-23 15:18:04 +02:00
Backend: rediriger vers la fiche apres creation d'un adherent
Le login et le mot de passe temporaire s'affichent sur la fiche de l'adherent. Apres creation, AddMemberPanel redirige desormais vers /backend/adherents/[id] pour les rendre visibles immediatement. addMember retourne l'id du nouvel adherent. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
4193d8e914
commit
e2dc695d3e
2 files changed
+8
-3
No files matched your search
@@ -114,12 +114,12 @@ export async function publishPromo(formData: FormData) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ---- Members CRUD ----
|
// ---- Members CRUD ----
|
||||||
export async function addMember(formData: FormData) {
|
export async function addMember(formData: FormData): Promise<number | undefined> {
|
||||||
const { role } = await requireRole();
|
const { role } = await requireRole();
|
||||||
if (!can(role, "manageMembers")) throw new Error("Accès refusé");
|
if (!can(role, "manageMembers")) throw new Error("Accès refusé");
|
||||||
|
|
||||||
const name = String(formData.get("name") ?? "").trim();
|
const name = String(formData.get("name") ?? "").trim();
|
||||||
if (!name) return;
|
if (!name) return undefined;
|
||||||
const email = String(formData.get("email") ?? "").trim().toLowerCase();
|
const email = String(formData.get("email") ?? "").trim().toLowerCase();
|
||||||
if (!email) throw new Error("L'e-mail est requis pour créer le compte de l'adhérent.");
|
if (!email) throw new Error("L'e-mail est requis pour créer le compte de l'adhérent.");
|
||||||
const categoryId = formData.get("categoryId") ? Number(formData.get("categoryId")) : null;
|
const categoryId = formData.get("categoryId") ? Number(formData.get("categoryId")) : null;
|
||||||
@@ -154,6 +154,7 @@ export async function addMember(formData: FormData) {
|
|||||||
revalidatePath("/backend/adherents");
|
revalidatePath("/backend/adherents");
|
||||||
revalidatePath("/backend");
|
revalidatePath("/backend");
|
||||||
revalidatePath("/");
|
revalidatePath("/");
|
||||||
|
return newMember.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Crée des comptes de connexion pour les adhérents existants qui n'en ont pas
|
// Crée des comptes de connexion pour les adhérents existants qui n'en ont pas
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
import { addMember } from "../actions";
|
import { addMember } from "../actions";
|
||||||
|
|
||||||
export function AddMemberPanel({
|
export function AddMemberPanel({
|
||||||
@@ -9,6 +10,7 @@ export function AddMemberPanel({
|
|||||||
categories: { id: number; label: string }[];
|
categories: { id: number; label: string }[];
|
||||||
}) {
|
}) {
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={{ display: "flex", flexDirection: "column", gap: 0 }}>
|
<div style={{ display: "flex", flexDirection: "column", gap: 0 }}>
|
||||||
@@ -25,8 +27,10 @@ export function AddMemberPanel({
|
|||||||
{open && (
|
{open && (
|
||||||
<form
|
<form
|
||||||
action={async (fd) => {
|
action={async (fd) => {
|
||||||
await addMember(fd);
|
const id = await addMember(fd);
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
|
// Redirige vers la fiche : le login + mot de passe temporaire y sont affichés.
|
||||||
|
if (id) router.push(`/backend/adherents/${id}`);
|
||||||
}}
|
}}
|
||||||
style={{ background: "#fff", border: "1px solid #e6dcc6", borderRadius: 16, padding: 22, marginTop: 14 }}
|
style={{ background: "#fff", border: "1px solid #e6dcc6", borderRadius: 16, padding: 22, marginTop: 14 }}
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in new issue
Block a user