forked from fahrPool/fahrPool
fix: render Sperren button within a single row Card instead of a duplicate row
This commit is contained in:
parent
a85b79bb05
commit
d261061c1c
|
|
@ -46,121 +46,51 @@ export function NutzerZeile({ nutzer, eigeneId }: { nutzer: Nutzer; eigeneId: st
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
const sperrenButton = (
|
||||||
<>
|
<Button
|
||||||
{!bearbeiten ? (
|
type="button"
|
||||||
<Card
|
fullWidth={false}
|
||||||
role="row"
|
variant={nutzer.gesperrt ? "secondary" : "destructive"}
|
||||||
className="md:grid md:grid-cols-[1fr_1fr_auto_auto_auto] md:items-center md:gap-4 md:rounded-none md:border-0 md:border-b md:p-0 md:px-4 md:py-3 md:shadow-none"
|
disabled={istEigenerAccount || isSperrenPending}
|
||||||
>
|
onClick={handleSperren}
|
||||||
<div role="cell">
|
>
|
||||||
<span className="text-xs font-medium text-asphalt-grey md:hidden">Name</span>
|
{nutzer.gesperrt ? "Entsperren" : "Sperren"}
|
||||||
<p className="text-asphalt-grey">{nutzer.name}</p>
|
</Button>
|
||||||
</div>
|
);
|
||||||
<div role="cell" className="mt-2 md:mt-0">
|
|
||||||
<span className="text-xs font-medium text-asphalt-grey md:hidden">E-Mail</span>
|
if (!bearbeiten) {
|
||||||
<p className="text-asphalt-grey">{nutzer.email ?? "—"}</p>
|
return (
|
||||||
</div>
|
|
||||||
<div role="cell" className="mt-2 md:mt-0">
|
|
||||||
<span className="text-xs font-medium text-asphalt-grey md:hidden">Rolle</span>
|
|
||||||
<p className="text-asphalt-grey">{nutzer.role}</p>
|
|
||||||
</div>
|
|
||||||
<div role="cell" className="mt-2 md:mt-0">
|
|
||||||
<span className="text-xs font-medium text-asphalt-grey md:hidden">Status</span>
|
|
||||||
<p className={nutzer.gesperrt ? "text-status-danger" : "text-asphalt-grey"}>
|
|
||||||
{nutzer.gesperrt ? "Gesperrt" : "Aktiv"}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<div role="cell" className="mt-3 flex flex-wrap items-center gap-3 md:mt-0">
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={() => setBearbeiten(true)}
|
|
||||||
className="min-h-11 text-sm text-performance-blue hover:underline"
|
|
||||||
>
|
|
||||||
Bearbeiten
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</Card>
|
|
||||||
) : (
|
|
||||||
<Card role="row" className="md:rounded-none md:border-0 md:border-b">
|
|
||||||
<form
|
|
||||||
onSubmit={handleSubmit}
|
|
||||||
className="flex flex-col gap-3 md:grid md:grid-cols-[1fr_1fr_1fr_auto_auto] md:items-end md:gap-4"
|
|
||||||
>
|
|
||||||
{fehler && (
|
|
||||||
<div className="md:col-span-5">
|
|
||||||
<Alert>{fehler}</Alert>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
<FormField label="Name" htmlFor={`name-${nutzer.id}`}>
|
|
||||||
<input
|
|
||||||
id={`name-${nutzer.id}`}
|
|
||||||
name="name"
|
|
||||||
type="text"
|
|
||||||
required
|
|
||||||
defaultValue={nutzer.name}
|
|
||||||
className={FIELD_CLASSES}
|
|
||||||
/>
|
|
||||||
</FormField>
|
|
||||||
<FormField label="E-Mail" htmlFor={`email-${nutzer.id}`}>
|
|
||||||
<input
|
|
||||||
id={`email-${nutzer.id}`}
|
|
||||||
name="email"
|
|
||||||
type="email"
|
|
||||||
required
|
|
||||||
defaultValue={nutzer.email ?? ""}
|
|
||||||
className={FIELD_CLASSES}
|
|
||||||
/>
|
|
||||||
</FormField>
|
|
||||||
{istEigenerAccount ? (
|
|
||||||
<div>
|
|
||||||
<span className="mb-1 block text-sm font-medium text-asphalt-grey">Rolle</span>
|
|
||||||
<p className="text-asphalt-grey">{nutzer.role} (nicht selbst änderbar)</p>
|
|
||||||
<input type="hidden" name="rolle" value={nutzer.role} />
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<FormField label="Rolle" htmlFor={`rolle-${nutzer.id}`}>
|
|
||||||
<select id={`rolle-${nutzer.id}`} name="rolle" defaultValue={nutzer.role} className={FIELD_CLASSES}>
|
|
||||||
{GUELTIGE_ROLLEN.map((rolle) => (
|
|
||||||
<option key={rolle} value={rolle}>
|
|
||||||
{rolle}
|
|
||||||
</option>
|
|
||||||
))}
|
|
||||||
</select>
|
|
||||||
</FormField>
|
|
||||||
)}
|
|
||||||
<Button type="submit" fullWidth={false} disabled={isPending}>
|
|
||||||
Speichern
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
type="button"
|
|
||||||
variant="secondary"
|
|
||||||
fullWidth={false}
|
|
||||||
onClick={() => {
|
|
||||||
setBearbeiten(false);
|
|
||||||
setFehler(null);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Abbrechen
|
|
||||||
</Button>
|
|
||||||
</form>
|
|
||||||
</Card>
|
|
||||||
)}
|
|
||||||
<Card
|
<Card
|
||||||
role="row"
|
role="row"
|
||||||
className="md:grid md:grid-cols-[1fr_1fr_auto_auto_auto] md:items-center md:gap-4 md:rounded-none md:border-0 md:border-b md:p-0 md:px-4 md:py-3 md:shadow-none"
|
className="md:grid md:grid-cols-[1fr_1fr_auto_auto_auto] md:items-center md:gap-4 md:rounded-none md:border-0 md:border-b md:p-0 md:px-4 md:py-3 md:shadow-none"
|
||||||
>
|
>
|
||||||
<div role="cell" className="md:col-span-4" />
|
<div role="cell">
|
||||||
|
<span className="text-xs font-medium text-asphalt-grey md:hidden">Name</span>
|
||||||
|
<p className="text-asphalt-grey">{nutzer.name}</p>
|
||||||
|
</div>
|
||||||
|
<div role="cell" className="mt-2 md:mt-0">
|
||||||
|
<span className="text-xs font-medium text-asphalt-grey md:hidden">E-Mail</span>
|
||||||
|
<p className="text-asphalt-grey">{nutzer.email ?? "—"}</p>
|
||||||
|
</div>
|
||||||
|
<div role="cell" className="mt-2 md:mt-0">
|
||||||
|
<span className="text-xs font-medium text-asphalt-grey md:hidden">Rolle</span>
|
||||||
|
<p className="text-asphalt-grey">{nutzer.role}</p>
|
||||||
|
</div>
|
||||||
|
<div role="cell" className="mt-2 md:mt-0">
|
||||||
|
<span className="text-xs font-medium text-asphalt-grey md:hidden">Status</span>
|
||||||
|
<p className={nutzer.gesperrt ? "text-status-danger" : "text-asphalt-grey"}>
|
||||||
|
{nutzer.gesperrt ? "Gesperrt" : "Aktiv"}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
<div role="cell" className="mt-3 flex flex-wrap items-center gap-3 md:mt-0">
|
<div role="cell" className="mt-3 flex flex-wrap items-center gap-3 md:mt-0">
|
||||||
<Button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
fullWidth={false}
|
onClick={() => setBearbeiten(true)}
|
||||||
variant={nutzer.gesperrt ? "secondary" : "destructive"}
|
className="min-h-11 text-sm text-performance-blue hover:underline"
|
||||||
disabled={istEigenerAccount || isSperrenPending}
|
|
||||||
onClick={handleSperren}
|
|
||||||
>
|
>
|
||||||
{nutzer.gesperrt ? "Entsperren" : "Sperren"}
|
Bearbeiten
|
||||||
</Button>
|
</button>
|
||||||
|
{sperrenButton}
|
||||||
</div>
|
</div>
|
||||||
{sperrenFehler && (
|
{sperrenFehler && (
|
||||||
<div className="md:col-span-5">
|
<div className="md:col-span-5">
|
||||||
|
|
@ -168,6 +98,80 @@ export function NutzerZeile({ nutzer, eigeneId }: { nutzer: Nutzer; eigeneId: st
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</Card>
|
</Card>
|
||||||
</>
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card role="row" className="md:rounded-none md:border-0 md:border-b">
|
||||||
|
<form
|
||||||
|
onSubmit={handleSubmit}
|
||||||
|
className="flex flex-col gap-3 md:grid md:grid-cols-[1fr_1fr_1fr_auto_auto] md:items-end md:gap-4"
|
||||||
|
>
|
||||||
|
{fehler && (
|
||||||
|
<div className="md:col-span-5">
|
||||||
|
<Alert>{fehler}</Alert>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<FormField label="Name" htmlFor={`name-${nutzer.id}`}>
|
||||||
|
<input
|
||||||
|
id={`name-${nutzer.id}`}
|
||||||
|
name="name"
|
||||||
|
type="text"
|
||||||
|
required
|
||||||
|
defaultValue={nutzer.name}
|
||||||
|
className={FIELD_CLASSES}
|
||||||
|
/>
|
||||||
|
</FormField>
|
||||||
|
<FormField label="E-Mail" htmlFor={`email-${nutzer.id}`}>
|
||||||
|
<input
|
||||||
|
id={`email-${nutzer.id}`}
|
||||||
|
name="email"
|
||||||
|
type="email"
|
||||||
|
required
|
||||||
|
defaultValue={nutzer.email ?? ""}
|
||||||
|
className={FIELD_CLASSES}
|
||||||
|
/>
|
||||||
|
</FormField>
|
||||||
|
{istEigenerAccount ? (
|
||||||
|
<div>
|
||||||
|
<span className="mb-1 block text-sm font-medium text-asphalt-grey">Rolle</span>
|
||||||
|
<p className="text-asphalt-grey">{nutzer.role} (nicht selbst änderbar)</p>
|
||||||
|
<input type="hidden" name="rolle" value={nutzer.role} />
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<FormField label="Rolle" htmlFor={`rolle-${nutzer.id}`}>
|
||||||
|
<select id={`rolle-${nutzer.id}`} name="rolle" defaultValue={nutzer.role} className={FIELD_CLASSES}>
|
||||||
|
{GUELTIGE_ROLLEN.map((rolle) => (
|
||||||
|
<option key={rolle} value={rolle}>
|
||||||
|
{rolle}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</FormField>
|
||||||
|
)}
|
||||||
|
<Button type="submit" fullWidth={false} disabled={isPending}>
|
||||||
|
Speichern
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="secondary"
|
||||||
|
fullWidth={false}
|
||||||
|
onClick={() => {
|
||||||
|
setBearbeiten(false);
|
||||||
|
setFehler(null);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Abbrechen
|
||||||
|
</Button>
|
||||||
|
</form>
|
||||||
|
<div className="mt-3 flex flex-wrap items-center gap-3">
|
||||||
|
{sperrenButton}
|
||||||
|
</div>
|
||||||
|
{sperrenFehler && (
|
||||||
|
<div className="mt-3">
|
||||||
|
<Alert>{sperrenFehler}</Alert>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</Card>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue