forked from baron/baron-sso
feat: enhance multi-tenant UI and fix member aggregation
- adminfront: Update TenantListPage and UserListPage sorting logic to support all columns dynamically - adminfront: Add inline 'Move', 'Remove', and 'Delete' actions directly inside the Tenant Org Chart member table - adminfront: Remove redundant 'ACTIONS' column and profile icon from UserListPage, making the name clickable - adminfront: Remove 'New Member' creation link from Tenant Org Chart 'Add Member' dropdown - backend: Fix CountByCompanyCodes query to accurately aggregate user counts using both primary company_code and company_codes array
This commit is contained in:
@@ -44,13 +44,6 @@ import {
|
||||
} from "../../components/ui/dialog";
|
||||
import { Input } from "../../components/ui/input";
|
||||
import { Label } from "../../components/ui/label";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "../../components/ui/select";
|
||||
import { Switch } from "../../components/ui/switch";
|
||||
import {
|
||||
Tabs,
|
||||
@@ -85,7 +78,6 @@ import {
|
||||
parseOrgChartTenantSelection,
|
||||
} from "./orgChartPicker";
|
||||
import type { UserSchemaField } from "./userSchemaFields";
|
||||
import { userStatusLabel, userStatusValues } from "./userStatus";
|
||||
|
||||
type UserFormValues = Omit<UserUpdateRequest, "metadata"> & {
|
||||
metadata: Record<string, Record<string, string | number | boolean>>;
|
||||
@@ -131,40 +123,12 @@ function createEmptyAppointment(): AppointmentDraft {
|
||||
tenantId: "",
|
||||
tenantName: "",
|
||||
tenantSlug: "",
|
||||
isPrimary: false,
|
||||
isOwner: false,
|
||||
jobTitle: "",
|
||||
position: "",
|
||||
};
|
||||
}
|
||||
|
||||
function normalizePrimaryAppointments(
|
||||
appointments: AppointmentDraft[],
|
||||
): AppointmentDraft[] {
|
||||
const leafIndexes = appointments
|
||||
.map((appointment, index) =>
|
||||
appointment.tenantId.trim().length > 0 ? index : -1,
|
||||
)
|
||||
.filter((index) => index >= 0);
|
||||
if (leafIndexes.length === 1) {
|
||||
const primaryIndex = leafIndexes[0];
|
||||
return appointments.map((appointment, index) => ({
|
||||
...appointment,
|
||||
isPrimary: index === primaryIndex,
|
||||
}));
|
||||
}
|
||||
const selectedIndex = appointments.findIndex(
|
||||
(appointment) => appointment.isPrimary === true,
|
||||
);
|
||||
return appointments.map((appointment, index) => ({
|
||||
...appointment,
|
||||
isPrimary:
|
||||
selectedIndex >= 0 &&
|
||||
index === selectedIndex &&
|
||||
appointment.tenantId.trim().length > 0,
|
||||
}));
|
||||
}
|
||||
|
||||
function validateManualPassword(
|
||||
password: string,
|
||||
policy?: PasswordPolicyResponse,
|
||||
@@ -521,17 +485,15 @@ function UserDetailPage() {
|
||||
try {
|
||||
const tenant = await resolveTenantSelection(selection, tenants);
|
||||
setAdditionalAppointments((current) =>
|
||||
normalizePrimaryAppointments(
|
||||
current.map((appointment, index) =>
|
||||
index === target.index
|
||||
? {
|
||||
...appointment,
|
||||
tenantId: tenant.id,
|
||||
tenantName: tenant.name,
|
||||
tenantSlug: tenant.slug,
|
||||
}
|
||||
: appointment,
|
||||
),
|
||||
current.map((appointment, index) =>
|
||||
index === target.index
|
||||
? {
|
||||
...appointment,
|
||||
tenantId: tenant.id,
|
||||
tenantName: tenant.name,
|
||||
tenantSlug: tenant.slug,
|
||||
}
|
||||
: appointment,
|
||||
),
|
||||
);
|
||||
setPickerTarget(null);
|
||||
@@ -574,30 +536,15 @@ function UserDetailPage() {
|
||||
patch: Partial<UserAppointment>,
|
||||
) => {
|
||||
setAdditionalAppointments((current) =>
|
||||
normalizePrimaryAppointments(
|
||||
current.map((appointment, currentIndex) =>
|
||||
currentIndex === index ? { ...appointment, ...patch } : appointment,
|
||||
),
|
||||
),
|
||||
);
|
||||
};
|
||||
|
||||
const setPrimaryAppointment = (index: number, checked: boolean) => {
|
||||
setAdditionalAppointments((current) =>
|
||||
normalizePrimaryAppointments(
|
||||
current.map((appointment, currentIndex) => ({
|
||||
...appointment,
|
||||
isPrimary: checked && currentIndex === index,
|
||||
})),
|
||||
current.map((appointment, currentIndex) =>
|
||||
currentIndex === index ? { ...appointment, ...patch } : appointment,
|
||||
),
|
||||
);
|
||||
};
|
||||
|
||||
const removeAppointment = (index: number) => {
|
||||
setAdditionalAppointments((current) =>
|
||||
normalizePrimaryAppointments(
|
||||
current.filter((_, currentIndex) => currentIndex !== index),
|
||||
),
|
||||
current.filter((_, currentIndex) => currentIndex !== index),
|
||||
);
|
||||
};
|
||||
|
||||
@@ -655,10 +602,7 @@ function UserDetailPage() {
|
||||
tenantSlug:
|
||||
user.companyCode ||
|
||||
user.joinedTenants?.find(
|
||||
(t) =>
|
||||
t.type === "COMPANY" ||
|
||||
t.type === "COMPANY_GROUP" ||
|
||||
t.type === "ORGANIZATION",
|
||||
(t) => t.type === "COMPANY" || t.type === "COMPANY_GROUP",
|
||||
)?.slug ||
|
||||
"",
|
||||
department: user.department || "",
|
||||
@@ -692,45 +636,38 @@ function UserDetailPage() {
|
||||
isHanmacFamilyTenant(tenant, tenants, hanmacFamilyTenantId),
|
||||
);
|
||||
setAdditionalAppointments(
|
||||
normalizePrimaryAppointments(
|
||||
Array.isArray(rawAppointments)
|
||||
? (rawAppointments as UserAppointment[]).map((appointment) => ({
|
||||
...appointment,
|
||||
isPrimary:
|
||||
appointment.isPrimary === true ||
|
||||
appointment.tenantId === metadata.primaryTenantId,
|
||||
draftId: createDraftId(),
|
||||
}))
|
||||
: isUserHanmacFamily
|
||||
? familyFallbackTenants.length > 0
|
||||
? familyFallbackTenants.map((tenant) => ({
|
||||
draftId: createDraftId(),
|
||||
tenantId: tenant.id,
|
||||
tenantName: tenant.name,
|
||||
tenantSlug: tenant.slug,
|
||||
isPrimary: tenant.id === fallbackAppointment?.id,
|
||||
isOwner:
|
||||
metadata.primaryTenantIsOwner === true &&
|
||||
tenant.id === fallbackAppointment?.id,
|
||||
jobTitle: user.jobTitle,
|
||||
position: user.position,
|
||||
}))
|
||||
: fallbackAppointment
|
||||
? [
|
||||
{
|
||||
draftId: createDraftId(),
|
||||
tenantId: fallbackAppointment.id,
|
||||
tenantName: fallbackAppointment.name,
|
||||
tenantSlug: fallbackAppointment.slug,
|
||||
isPrimary: true,
|
||||
isOwner: metadata.primaryTenantIsOwner === true,
|
||||
jobTitle: user.jobTitle,
|
||||
position: user.position,
|
||||
},
|
||||
]
|
||||
: []
|
||||
: [],
|
||||
),
|
||||
Array.isArray(rawAppointments)
|
||||
? (rawAppointments as UserAppointment[]).map((appointment) => ({
|
||||
...appointment,
|
||||
draftId: createDraftId(),
|
||||
}))
|
||||
: isUserHanmacFamily
|
||||
? familyFallbackTenants.length > 0
|
||||
? familyFallbackTenants.map((tenant) => ({
|
||||
draftId: createDraftId(),
|
||||
tenantId: tenant.id,
|
||||
tenantName: tenant.name,
|
||||
tenantSlug: tenant.slug,
|
||||
isOwner:
|
||||
metadata.primaryTenantIsOwner === true &&
|
||||
tenant.id === fallbackAppointment?.id,
|
||||
jobTitle: user.jobTitle,
|
||||
position: user.position,
|
||||
}))
|
||||
: fallbackAppointment
|
||||
? [
|
||||
{
|
||||
draftId: createDraftId(),
|
||||
tenantId: fallbackAppointment.id,
|
||||
tenantName: fallbackAppointment.name,
|
||||
tenantSlug: fallbackAppointment.slug,
|
||||
isOwner: metadata.primaryTenantIsOwner === true,
|
||||
jobTitle: user.jobTitle,
|
||||
position: user.position,
|
||||
},
|
||||
]
|
||||
: []
|
||||
: [],
|
||||
);
|
||||
}
|
||||
}, [hanmacFamilyTenantId, tenants, user, reset]);
|
||||
@@ -811,37 +748,19 @@ function UserDetailPage() {
|
||||
tenantId: appointment.tenantId,
|
||||
tenantSlug: appointment.tenantSlug,
|
||||
tenantName: appointment.tenantName,
|
||||
isPrimary: appointment.isPrimary === true,
|
||||
isOwner: appointment.isOwner,
|
||||
jobTitle: appointment.jobTitle,
|
||||
position: appointment.position,
|
||||
}));
|
||||
const primaryAppointment = appointments.find(
|
||||
(appointment) => appointment.isPrimary,
|
||||
);
|
||||
|
||||
payload.tenantSlug = undefined;
|
||||
payload.department = undefined;
|
||||
payload.position = undefined;
|
||||
payload.jobTitle = undefined;
|
||||
payload.additionalAppointments = appointments;
|
||||
if (primaryAppointment) {
|
||||
payload.tenantSlug = primaryAppointment.tenantSlug;
|
||||
payload.primaryTenantId = primaryAppointment.tenantId;
|
||||
payload.primaryTenantName = primaryAppointment.tenantName;
|
||||
payload.primaryTenantIsOwner = primaryAppointment.isOwner;
|
||||
}
|
||||
payload.metadata = {
|
||||
...metadata,
|
||||
additionalAppointments: appointments,
|
||||
...(primaryAppointment
|
||||
? {
|
||||
primaryTenantId: primaryAppointment.tenantId,
|
||||
primaryTenantName: primaryAppointment.tenantName,
|
||||
primaryTenantSlug: primaryAppointment.tenantSlug,
|
||||
primaryTenantIsOwner: primaryAppointment.isOwner,
|
||||
}
|
||||
: {}),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -872,9 +791,6 @@ function UserDetailPage() {
|
||||
filterNonHanmacFamilyTenants(userAffiliatedTenants, hanmacFamilyTenantId),
|
||||
[userAffiliatedTenants, hanmacFamilyTenantId],
|
||||
);
|
||||
const primaryAppointmentLeafCount = additionalAppointments.filter(
|
||||
(appointment) => appointment.tenantId.trim().length > 0,
|
||||
).length;
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
@@ -941,10 +857,7 @@ function UserDetailPage() {
|
||||
{user.tenant?.name ||
|
||||
user.companyCode ||
|
||||
user.joinedTenants?.find(
|
||||
(t) =>
|
||||
t.type === "COMPANY" ||
|
||||
t.type === "COMPANY_GROUP" ||
|
||||
t.type === "ORGANIZATION",
|
||||
(t) => t.type === "COMPANY" || t.type === "COMPANY_GROUP",
|
||||
)?.name ||
|
||||
t("ui.admin.users.detail.form.tenant_global", "시스템 전역")}
|
||||
</Badge>
|
||||
@@ -1088,23 +1001,21 @@ function UserDetailPage() {
|
||||
>
|
||||
{t("ui.admin.users.detail.form.status", "상태")}
|
||||
</Label>
|
||||
<Select
|
||||
value={watchedStatus || "inactive"}
|
||||
onValueChange={(status) => setValue("status", status)}
|
||||
>
|
||||
<SelectTrigger id="status" className="h-11">
|
||||
<SelectValue>
|
||||
{userStatusLabel(watchedStatus || "inactive")}
|
||||
</SelectValue>
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{userStatusValues.map((status) => (
|
||||
<SelectItem key={status} value={status}>
|
||||
{userStatusLabel(status)}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<div className="flex h-11 items-center gap-3 rounded-md border border-input bg-background px-3">
|
||||
<Switch
|
||||
id="status"
|
||||
checked={watchedStatus === "active"}
|
||||
onCheckedChange={(checked) =>
|
||||
setValue("status", checked ? "active" : "inactive")
|
||||
}
|
||||
/>
|
||||
<span className="text-sm text-muted-foreground">
|
||||
{t(
|
||||
`ui.common.status.${watchedStatus}`,
|
||||
watchedStatus || "inactive",
|
||||
)}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1249,26 +1160,6 @@ function UserDetailPage() {
|
||||
{appointment.tenantSlug}
|
||||
</span>
|
||||
)}
|
||||
<label className="flex items-center gap-3 text-sm">
|
||||
<Switch
|
||||
aria-label={t(
|
||||
"ui.admin.users.detail.form.appointment_primary",
|
||||
"대표 조직",
|
||||
)}
|
||||
checked={appointment.isPrimary === true}
|
||||
disabled={
|
||||
!appointment.tenantId ||
|
||||
primaryAppointmentLeafCount <= 1
|
||||
}
|
||||
onCheckedChange={(checked) =>
|
||||
setPrimaryAppointment(index, checked)
|
||||
}
|
||||
/>
|
||||
{t(
|
||||
"ui.admin.users.detail.form.appointment_primary",
|
||||
"대표 조직",
|
||||
)}
|
||||
</label>
|
||||
<label className="flex items-center gap-3 text-sm">
|
||||
<Checkbox
|
||||
checked={appointment.isOwner}
|
||||
|
||||
Reference in New Issue
Block a user