Skip to main content

All Profiles

All Profiles provides comprehensive user management across the platform, allowing admins to view, filter, and manage all user accounts including parents and therapists. This system handles user lifecycle management with critical business logic for registration completion, role assignment, and account status management.

Core Concepts

  • User Types: Parent and Therapist roles with different access levels and capabilities
  • Registration Status: Complete vs Incomplete registration tracking
  • Account Status: Active vs Deleted accounts with soft delete functionality
  • Role-Based Actions: Different management options based on user role and registration status
  • Bulk Operations: Multi-user selection and batch operations for efficiency

Web/Admin Capabilities

1) List & Filter

Business Rules:

  • Filter by registration status (Complete/Incomplete), user type (Parent/Therapist), and account status (Active/Deleted)
  • Search across name, email, and phone number fields
  • Sort by name, email, phone, or creation date
  • Support for UUID-based search for direct user lookup
  • Pagination with configurable page sizes

Implementation:

// Filter logic with role-based access and search capabilities
const filterOptions: FilterOptions<Users_Bool_Exp> = {
[language.allProfiles.filters.registrationStatus.label]: {
options: [
{ value: true, display: 'Completed', disabled: false },
{ value: false, display: 'Incomplete', disabled: false },
],
table_key: { is_registered: { _in: [] } },
},
[language.allProfiles.filters.userType.label]: {
options: [
{
value: 'parent',
display: 'Parent',
custom_filter: { parent: { id: { _is_null: false } } },
},
{
value: 'therapist',
display: 'Therapist',
custom_filter: { therapists: { id: { _is_null: false } } },
},
],
table_key: { id: { _is_null: true } },
},
[language.allProfiles.filters.accountStatus.label]: {
options: [
{ value: false, display: 'Active', disabled: false },
{ value: true, display: 'Deleted', disabled: false },
],
table_key: { isDeleted: { _in: [] } },
},
};

// Search implementation with UUID detection
const searchObj = isUUID(searchStr)
? {
_or: [
{ name: { _ilike: `%${searchStr}%` } },
{ phone: { _ilike: `%${searchStr}%` } },
{ email: { _ilike: `%${searchStr}%` } },
{ id: { _eq: searchStr } },
],
}
: {
_or: [
{ name: { _ilike: `%${searchStr}%` } },
{ phone: { _ilike: `%${searchStr}%` } },
{ email: { _ilike: `%${searchStr}%` } },
],
};

2) User Management Operations

User Management Business Rules:

  • Role-Based Actions: Different actions available based on user role and registration status
  • Registration Completion: Incomplete users can be completed as either parent or therapist
  • Soft Delete: Users are soft deleted with ability to restore
  • Bulk Operations: Multiple user selection for batch operations
  • Navigation: Direct navigation to role-specific management pages

Action Logic:

// Role-based action determination
const getUserActions = (user: Users) => {
const actions = [];

if (user.isDeleted) {
actions.push('undoDelete');
} else {
if (
user.role === Roles_Enum_Enum.Therapist &&
user.is_registered &&
user.therapists?.[0]?.id
) {
actions.push('edit');
}
if (user.role === Roles_Enum_Enum.Parent && user.is_registered && user.id) {
actions.push('edit');
}
if (!user.is_registered) {
actions.push('completeAsParent', 'completeAsTherapist');
}
actions.push('delete');
}

return actions;
};

// Navigation logic based on user role
const handleRowClick = (user: Users) => {
if (user.role === Roles_Enum_Enum.Parent) {
router.push(`/parent/${user.id}`);
} else if (user.role === Roles_Enum_Enum.Therapist) {
router.push(`/therapist-management/therapist/${user.therapists?.[0]?.id}`);
}
};

GraphQL Implementation:

import { gql, ApolloClient } from '@apollo/client';

const GET_ALL_PROFILES = gql`
query GetAllProfilesList(
$limit: Int
$offset: Int
$where: users_bool_exp
$order_by: [users_order_by!]
) {
users(limit: $limit, offset: $offset, where: $where, order_by: $order_by) {
id
name
email
phone
role
is_registered
isDeleted
created_at
parent {
id
}
therapists {
id
}
}
users_aggregate(where: $where) {
aggregate {
count
}
}
}
`;

const DELETE_USERS = gql`
mutation DeleteUsers($in: [uuid!]!, $delete_at: timestamptz!) {
update_users(
where: { id: { _in: $in } }
_set: { isDeleted: true, deleted_at: $delete_at }
) {
affected_rows
}
}
`;

const UNDO_DELETE_USERS = gql`
mutation UndoDeletedUsers($in: [uuid!]!) {
update_users(
where: { id: { _in: $in } }
_set: { isDeleted: false, deleted_at: null }
) {
affected_rows
}
}
`;

async function getAllProfiles(
client: ApolloClient<unknown>,
variables: {
limit: number;
offset: number;
where?: Users_Bool_Exp;
order_by?: Users_Order_By[];
},
) {
const { data } = await client.query({
query: GET_ALL_PROFILES,
variables,
fetchPolicy: 'cache-and-network',
});

return {
users: data.users,
totalCount: data.users_aggregate.aggregate?.count || 0,
};
}

async function deleteUsers(client: ApolloClient<unknown>, userIds: string[]) {
const { data } = await client.mutate({
mutation: DELETE_USERS,
variables: {
in: userIds,
delete_at: new Date().toISOString(),
},
});

return data.update_users?.affected_rows || 0;
}

async function undoDeleteUsers(
client: ApolloClient<unknown>,
userIds: string[],
) {
const { data } = await client.mutate({
mutation: UNDO_DELETE_USERS,
variables: { in: userIds },
});

return data.update_users?.affected_rows || 0;
}

3) User Creation & Profile Completion

Profile Creation Business Rules:

  • Role Selection: Admins can create users as either parent or therapist
  • Registration Completion: Incomplete users can be completed with appropriate role
  • Form Navigation: Direct navigation to role-specific creation forms
  • Validation: Role-specific validation and requirements

Creation Logic:

// Profile type selection and navigation
const handleProfileTypeSelect = (type: 'parent' | 'therapist') => {
if (type === 'parent') {
router.push('/add-parent');
} else if (type === 'therapist') {
router.push('/therapist-management/add');
}
};

// Complete incomplete user registration
const completeUserRegistration = (
user: Users,
role: 'parent' | 'therapist',
) => {
if (role === 'parent') {
router.push(`/add-parent?userId=${user.id}`);
} else {
router.push(`/therapist-management/add?userId=${user.id}`);
}
};

4) Bulk Operations & Management

Bulk Operations Business Rules:

  • Multi-Selection: Select multiple users for batch operations
  • Bulk Delete: Delete multiple users simultaneously
  • Selection Validation: Only active users can be selected
  • Confirmation: Confirmation dialogs for destructive operations

Bulk Operations Implementation:

// Multi-user selection and bulk operations
const [selectedUsers, setSelectedUsers] = useState<Users[]>([]);

const handleSelectedRowsChange = useCallback((rows: Users[]) => {
setSelectedUsers(rows);
}, []);

const deleteMultipleUsers = () => {
if (loadingDelete || selectedUsers.length === 0) return;

promptDelete({
content: (
<p>
{language.allProfiles.deleteConfirmation.multipleUsers}{' '}
<span className="font-bold">
{selectedUsers.length > 1
? `${selectedUsers.length} ${language.allProfiles.deleteConfirmation.users}`
: language.allProfiles.deleteConfirmation.thisUser}
</span>
</p>
),
onSave() {
deleteUsersMutation({
variables: {
in: selectedUsers.map((user) => user.id),
delete_at: new Date().toISOString(),
},
});
},
});
};

// Row selection validation
const isRowSelectable = (row: Users) => row && !row.isDeleted;

Data Flow (Web ↔ Backend)

Critical Business Logic Flow:

  1. User Listing: Load users → Apply filters → Search → Sort → Paginate
  2. User Actions: Determine available actions → Execute role-specific operations → Navigate to appropriate forms
  3. Bulk Operations: Select users → Validate selection → Execute batch operations → Update UI
  4. User Management: Create/Edit users → Complete registrations → Manage account status

GraphQL Operations with Business Rules:

ActionOperationBusiness Rules
List UsersgetAllProfilesList(where, order_by)Role-based filtering, search across multiple fields
Delete UsersdeleteUsers(in, delete_at)Soft delete with timestamp, bulk operations
Restore UsersundoDeletedUsers(in)Restore soft-deleted users
User ActionsNavigationRole-based routing to appropriate management pages

Error Handling & Validation:

  • User Not Found: "User not found or access denied"
  • Bulk Operation Failed: "Failed to delete selected users"
  • Invalid Role: "Invalid user role for this operation"
  • Selection Error: "Cannot select deleted users"

Security & Access Control

  • Admin-Only Access: Only admins can view and manage all user profiles
  • Role-Based Actions: Actions available based on user role and registration status
  • Soft Delete: Users are soft deleted to maintain data integrity
  • Audit Trail: All user management actions are logged with timestamps
  • Data Privacy: User data protected by role-based permissions and access controls