task h.1 adn fix permission

This commit is contained in:
phaichayon
2026-06-16 15:13:14 +07:00
parent 9ae41e4f2c
commit 90ee59d388
29 changed files with 3807 additions and 119 deletions

View File

@@ -1,3 +1,5 @@
import type { BusinessRole } from '@/lib/auth/rbac';
export interface UserOrganization {
id: string;
name: string;
@@ -8,13 +10,7 @@ export interface UserMembership {
organizationId: string;
organizationName: string;
membershipRole: 'admin' | 'user';
businessRole:
| 'it_admin'
| 'helpdesk'
| 'infrastructure'
| 'application'
| 'auditor'
| 'viewer';
businessRole: BusinessRole;
}
export interface User {
@@ -54,12 +50,6 @@ export type UserMutationPayload = {
memberships: Array<{
organizationId: string;
membershipRole: 'admin' | 'user';
businessRole:
| 'it_admin'
| 'helpdesk'
| 'infrastructure'
| 'application'
| 'auditor'
| 'viewer';
businessRole: BusinessRole;
}>;
};

View File

@@ -25,6 +25,7 @@ import { createUserMutation, updateUserMutation } from '../api/mutations';
import type { User } from '../api/types';
import { toast } from 'sonner';
import { type UserFormValues, userSchema } from '../schemas/user';
import type { BusinessRole } from '@/lib/auth/rbac';
interface UserFormSheetProps {
user?: User;
@@ -46,12 +47,11 @@ const membershipRoleOptions = [
] as const;
const businessRoleOptions = [
{ value: 'it_admin', label: 'IT Admin' },
{ value: 'helpdesk', label: 'Helpdesk' },
{ value: 'infrastructure', label: 'Infrastructure' },
{ value: 'application', label: 'Application' },
{ value: 'auditor', label: 'Auditor' },
{ value: 'viewer', label: 'Viewer' }
{ value: 'sales_manager', label: 'Sales Manager' },
{ value: 'sales', label: 'Sales' },
{ value: 'sales_support', label: 'Sales Support' },
{ value: 'department_manager', label: 'Department Manager' },
{ value: 'top_manager', label: 'Top Manager' }
] as const;
export function UserFormSheet({ user, open, onOpenChange }: UserFormSheetProps) {
@@ -194,7 +194,9 @@ export function UserFormSheet({ user, open, onOpenChange }: UserFormSheetProps)
label={isEdit ? 'Password (optional)' : 'Password'}
required={!isEdit}
type='password'
placeholder={isEdit ? 'Leave blank to keep current password' : 'Minimum 8 characters'}
placeholder={
isEdit ? 'Leave blank to keep current password' : 'Minimum 8 characters'
}
/>
{isEdit && user?.systemRole === 'super_admin' && (
@@ -254,7 +256,7 @@ export function UserFormSheet({ user, open, onOpenChange }: UserFormSheetProps)
{
organizationId: organization.id,
membershipRole: 'user',
businessRole: 'viewer'
businessRole: 'sales_support'
}
]);
field.handleBlur();
@@ -298,7 +300,7 @@ export function UserFormSheet({ user, open, onOpenChange }: UserFormSheetProps)
</Select>
<Select
value={membership?.businessRole ?? 'viewer'}
value={membership?.businessRole ?? 'sales_support'}
disabled={!checked}
onValueChange={(value) => {
field.handleChange(
@@ -306,13 +308,7 @@ export function UserFormSheet({ user, open, onOpenChange }: UserFormSheetProps)
item.organizationId === organization.id
? {
...item,
businessRole: value as
| 'it_admin'
| 'helpdesk'
| 'infrastructure'
| 'application'
| 'auditor'
| 'viewer'
businessRole: value as BusinessRole
}
: item
)

View File

@@ -1,4 +1,5 @@
import * as z from 'zod';
import { BUSINESS_ROLES } from '@/lib/auth/rbac';
export const userSchema = z.object({
name: z.string().min(2, 'Name must be at least 2 characters'),
@@ -10,14 +11,7 @@ export const userSchema = z.object({
z.object({
organizationId: z.string().min(1),
membershipRole: z.enum(['admin', 'user']),
businessRole: z.enum([
'it_admin',
'helpdesk',
'infrastructure',
'application',
'auditor',
'viewer'
])
businessRole: z.enum(BUSINESS_ROLES)
})
)
.min(1, 'Select at least one organization')