bugfix: a new flow added to re-enable disabled staffs.
This commit is contained in:
@@ -16,7 +16,7 @@ import {
|
||||
formatAccessSummary,
|
||||
type FeaturePermState,
|
||||
} from '../../../components/staff/staff-permission-form';
|
||||
import { Pencil, Trash2, Copy, Check, X, UserX } from 'lucide-react';
|
||||
import { Pencil, Trash2, Copy, Check, X, UserX, UserCheck } from 'lucide-react';
|
||||
import { DialogCloseButton } from '@/components/ui/shared/DialogCloseButton';
|
||||
import { useAuth } from '@/lib/hooks/useAuth';
|
||||
import { staffApi, type StaffMemberDto } from '@/lib/api/staff';
|
||||
@@ -67,6 +67,10 @@ function canDisableStaff(member: StaffMemberDto): boolean {
|
||||
return !member.isOwner && member.isActive;
|
||||
}
|
||||
|
||||
function canEnableStaff(member: StaffMemberDto): boolean {
|
||||
return !member.isOwner && member.invitationStatus === 'DISABLED';
|
||||
}
|
||||
|
||||
function PermissionGrid({
|
||||
state,
|
||||
onChange,
|
||||
@@ -161,6 +165,8 @@ export default function StaffPage() {
|
||||
const [editLoading, setEditLoading] = useState(false);
|
||||
const [disableTarget, setDisableTarget] = useState<StaffMemberDto | null>(null);
|
||||
const [disablingMembershipId, setDisablingMembershipId] = useState<string | null>(null);
|
||||
const [enableTarget, setEnableTarget] = useState<StaffMemberDto | null>(null);
|
||||
const [enablingMembershipId, setEnablingMembershipId] = useState<string | null>(null);
|
||||
|
||||
const canEdit = useMemo(() => canEditStaff(currentOrganization), [currentOrganization]);
|
||||
const hasActivePlan = Boolean(currentOrganization?.plan);
|
||||
@@ -170,6 +176,12 @@ export default function StaffPage() {
|
||||
return seats.used >= seats.limit;
|
||||
}, [seats]);
|
||||
|
||||
const hasAvailableSeat = useMemo(() => {
|
||||
if (!seats || seats.unlimited) return true;
|
||||
if (seats.limit == null) return true;
|
||||
return seats.used < seats.limit;
|
||||
}, [seats]);
|
||||
|
||||
const load = useCallback(async () => {
|
||||
toast.setError('');
|
||||
setLoading(true);
|
||||
@@ -352,6 +364,23 @@ export default function StaffPage() {
|
||||
}
|
||||
}
|
||||
|
||||
async function confirmEnableMember() {
|
||||
if (!enableTarget || !canEnableStaff(enableTarget) || !hasAvailableSeat) return;
|
||||
|
||||
setEnablingMembershipId(enableTarget.id);
|
||||
toast.setError('');
|
||||
try {
|
||||
await staffApi.enableMember(enableTarget.id);
|
||||
toast.showSuccess(`${enableTarget.name} was enabled and can sign in again.`);
|
||||
setEnableTarget(null);
|
||||
await load();
|
||||
} catch (e) {
|
||||
toast.showError(formatApiErrorMessage(e, 'Failed to enable member.'));
|
||||
} finally {
|
||||
setEnablingMembershipId(null);
|
||||
}
|
||||
}
|
||||
|
||||
if (!currentOrganization || !canViewStaff(currentOrganization)) {
|
||||
return (
|
||||
<p className="text-sm text-text-secondary">Redirecting…</p>
|
||||
@@ -547,6 +576,25 @@ export default function StaffPage() {
|
||||
)}
|
||||
</button>
|
||||
)}
|
||||
{canEnableStaff(m) && (
|
||||
<button
|
||||
type="button"
|
||||
className={`p-2 rounded-md ${
|
||||
canEdit
|
||||
? 'text-text-secondary hover:bg-background-card/80 hover:text-primary'
|
||||
: 'text-text-muted opacity-50 cursor-not-allowed'
|
||||
}`}
|
||||
aria-label="Enable member"
|
||||
disabled={!canEdit || enablingMembershipId === m.id}
|
||||
title="Enable member (uses a seat)"
|
||||
onClick={() => {
|
||||
if (!canEdit) return;
|
||||
setEnableTarget(m);
|
||||
}}
|
||||
>
|
||||
<UserCheck className="w-4 h-4" />
|
||||
</button>
|
||||
)}
|
||||
{canDisableStaff(m) && (
|
||||
<button
|
||||
type="button"
|
||||
@@ -660,6 +708,66 @@ export default function StaffPage() {
|
||||
</div>
|
||||
)}
|
||||
|
||||
{enableTarget && (
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/55">
|
||||
<div
|
||||
className="surface-card w-full max-w-md p-5 space-y-4 shadow-xl"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-labelledby="enable-staff-title"
|
||||
>
|
||||
<div className="flex items-start justify-between gap-2">
|
||||
<h2 id="enable-staff-title" className="text-lg font-semibold text-text-primary pr-2">
|
||||
Enable team member
|
||||
</h2>
|
||||
<DialogCloseButton
|
||||
onClick={() => {
|
||||
if (enablingMembershipId) return;
|
||||
setEnableTarget(null);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<p className="text-sm text-text-secondary">
|
||||
Enable <span className="font-medium text-text-primary">{enableTarget.name}</span> (
|
||||
{enableTarget.email})?
|
||||
</p>
|
||||
<ul className="text-sm text-text-secondary space-y-2 list-disc pl-5">
|
||||
<li>They can sign in to this organization again with their existing account.</li>
|
||||
<li>No new invitation is sent and no data was removed while they were disabled.</li>
|
||||
<li>
|
||||
Enabling uses <span className="text-text-primary font-medium">one seat</span> on your
|
||||
plan.
|
||||
</li>
|
||||
</ul>
|
||||
{!hasAvailableSeat && (
|
||||
<p className="text-sm text-amber-600 dark:text-amber-400">
|
||||
No seats are available. Disable another member or upgrade your plan before enabling
|
||||
this person.
|
||||
</p>
|
||||
)}
|
||||
<div className="flex justify-end gap-2 pt-1">
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
disabled={Boolean(enablingMembershipId)}
|
||||
onClick={() => setEnableTarget(null)}
|
||||
>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant="primary"
|
||||
isLoading={enablingMembershipId === enableTarget.id}
|
||||
disabled={Boolean(enablingMembershipId) || !hasAvailableSeat}
|
||||
onClick={() => void confirmEnableMember()}
|
||||
>
|
||||
Enable member
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{disableTarget && (
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/55">
|
||||
<div
|
||||
|
||||
@@ -8,10 +8,18 @@ import { Input } from '@/components/ui/shared/Input';
|
||||
import { Button } from '@/components/ui/shared/Button';
|
||||
|
||||
export function OrganizationSelectorContent() {
|
||||
const { organizations, selectOrganization, createOrganization, isLoading, error, clearError } = useAuth();
|
||||
const {
|
||||
organizations,
|
||||
currentOrganization,
|
||||
selectOrganization,
|
||||
createOrganization,
|
||||
isLoading,
|
||||
error,
|
||||
clearError,
|
||||
} = useAuth();
|
||||
const canCreateOrganization = useMemo(
|
||||
() => canUserCreateOrganization(organizations),
|
||||
[organizations],
|
||||
() => canCreateOrganizationFromCurrentOrg(currentOrganization),
|
||||
[currentOrganization],
|
||||
);
|
||||
const [isCreateOpen, setIsCreateOpen] = useState(false);
|
||||
const [organizationName, setOrganizationName] = useState('');
|
||||
|
||||
@@ -107,6 +107,13 @@ export const staffApi = {
|
||||
return response.data;
|
||||
},
|
||||
|
||||
enableMember: async (
|
||||
membershipId: string,
|
||||
): Promise<{ success: boolean; message: string }> => {
|
||||
const response = await apiClient.patch(`/staff/members/${membershipId}/enable`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
removeMember: async (
|
||||
membershipId: string,
|
||||
): Promise<{ success: boolean; message: string }> => {
|
||||
|
||||
Reference in New Issue
Block a user