update users,
This commit is contained in:
@@ -9,9 +9,9 @@ import { ArrowLeft as ArrowLeftIcon } from '@phosphor-icons/react/dist/ssr/Arrow
|
||||
|
||||
import { config } from '@/config';
|
||||
import { paths } from '@/paths';
|
||||
import { CustomerCreateForm } from '@/components/dashboard/student/student-create-form';
|
||||
import { UserCreateForm } from '@/components/dashboard/user/user-create-form';
|
||||
|
||||
export const metadata = { title: `Create | Customers | Dashboard | ${config.site.name}` } satisfies Metadata;
|
||||
export const metadata = { title: `Create | Users | Dashboard | ${config.site.name}` } satisfies Metadata;
|
||||
|
||||
export default function Page(): React.JSX.Element {
|
||||
return (
|
||||
@@ -29,19 +29,19 @@ export default function Page(): React.JSX.Element {
|
||||
<Link
|
||||
color="text.primary"
|
||||
component={RouterLink}
|
||||
href={paths.dashboard.customers.list}
|
||||
href={paths.dashboard.users.list}
|
||||
sx={{ alignItems: 'center', display: 'inline-flex', gap: 1 }}
|
||||
variant="subtitle2"
|
||||
>
|
||||
<ArrowLeftIcon fontSize="var(--icon-fontSize-md)" />
|
||||
Customers
|
||||
Users
|
||||
</Link>
|
||||
</div>
|
||||
<div>
|
||||
<Typography variant="h4">Create customer</Typography>
|
||||
<Typography variant="h4">Create user</Typography>
|
||||
</div>
|
||||
</Stack>
|
||||
<CustomerCreateForm />
|
||||
<UserCreateForm />
|
||||
</Stack>
|
||||
</Box>
|
||||
);
|
||||
|
@@ -11,10 +11,10 @@ import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { paths } from '@/paths';
|
||||
import { CrCategoryEditForm } from '@/components/dashboard/cr/categories/cr-category-edit-form';
|
||||
import { StudentEditForm } from '@/components/dashboard/student/student-edit-form';
|
||||
import { UserEditForm } from '@/components/dashboard/user/user-edit-form';
|
||||
|
||||
export default function Page(): React.JSX.Element {
|
||||
const { t } = useTranslation(['lp_categories']);
|
||||
const { t } = useTranslation(['users']);
|
||||
|
||||
React.useEffect(() => {
|
||||
// console.log('helloworld');
|
||||
@@ -35,7 +35,7 @@ export default function Page(): React.JSX.Element {
|
||||
<Link
|
||||
color="text.primary"
|
||||
component={RouterLink}
|
||||
href={paths.dashboard.students.list}
|
||||
href={paths.dashboard.users.list}
|
||||
sx={{ alignItems: 'center', display: 'inline-flex', gap: 1 }}
|
||||
variant="subtitle2"
|
||||
>
|
||||
@@ -47,7 +47,7 @@ export default function Page(): React.JSX.Element {
|
||||
<Typography variant="h4">{t('edit.title')}</Typography>
|
||||
</div>
|
||||
</Stack>
|
||||
<StudentEditForm />
|
||||
<UserEditForm />
|
||||
</Stack>
|
||||
</Box>
|
||||
);
|
11
002_source/cms/src/db/UserMetas/Create.tsx
Normal file
11
002_source/cms/src/db/UserMetas/Create.tsx
Normal file
@@ -0,0 +1,11 @@
|
||||
// api method for crate customer record
|
||||
// RULES:
|
||||
// TBA
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_CUSTOMERS } from '@/constants';
|
||||
import type { CreateFormProps } from '@/components/dashboard/customer/type.d';
|
||||
import type { RecordModel } from 'pocketbase';
|
||||
|
||||
export async function createCustomer(data: CreateFormProps): Promise<RecordModel> {
|
||||
return pb.collection(COL_CUSTOMERS).create(data);
|
||||
}
|
6
002_source/cms/src/db/UserMetas/Delete.tsx
Normal file
6
002_source/cms/src/db/UserMetas/Delete.tsx
Normal file
@@ -0,0 +1,6 @@
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_CUSTOMERS } from '@/constants';
|
||||
|
||||
export async function deleteCustomer(id: string): Promise<boolean> {
|
||||
return pb.collection(COL_CUSTOMERS).delete(id);
|
||||
}
|
9
002_source/cms/src/db/UserMetas/GetActiveCount.tsx
Normal file
9
002_source/cms/src/db/UserMetas/GetActiveCount.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
import { COL_CUSTOMERS } from '@/constants';
|
||||
import { pb } from '@/lib/pb';
|
||||
|
||||
export default async function GetActiveCount(): Promise<number> {
|
||||
const { totalItems: count } = await pb.collection(COL_CUSTOMERS).getList(1, 1, {
|
||||
filter: 'status = "active"',
|
||||
});
|
||||
return count;
|
||||
}
|
7
002_source/cms/src/db/UserMetas/GetAll.tsx
Normal file
7
002_source/cms/src/db/UserMetas/GetAll.tsx
Normal file
@@ -0,0 +1,7 @@
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_CUSTOMERS } from '@/constants';
|
||||
import { RecordModel } from 'pocketbase';
|
||||
|
||||
export async function getAllCustomers(options = {}): Promise<RecordModel[]> {
|
||||
return pb.collection(COL_CUSTOMERS).getFullList(options);
|
||||
}
|
9
002_source/cms/src/db/UserMetas/GetBlockedCount.tsx
Normal file
9
002_source/cms/src/db/UserMetas/GetBlockedCount.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
import { COL_CUSTOMERS } from '@/constants';
|
||||
import { pb } from '@/lib/pb';
|
||||
|
||||
export default async function GetBlockedCount(): Promise<number> {
|
||||
const { totalItems: count } = await pb.collection(COL_CUSTOMERS).getList(1, 1, {
|
||||
filter: 'status = "blocked"',
|
||||
});
|
||||
return count;
|
||||
}
|
7
002_source/cms/src/db/UserMetas/GetById.tsx
Normal file
7
002_source/cms/src/db/UserMetas/GetById.tsx
Normal file
@@ -0,0 +1,7 @@
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_CUSTOMERS } from '@/constants';
|
||||
import { RecordModel } from 'pocketbase';
|
||||
|
||||
export async function getCustomerById(id: string): Promise<RecordModel> {
|
||||
return pb.collection(COL_CUSTOMERS).getOne(id);
|
||||
}
|
9
002_source/cms/src/db/UserMetas/GetPendingCount.tsx
Normal file
9
002_source/cms/src/db/UserMetas/GetPendingCount.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
import { COL_CUSTOMERS } from '@/constants';
|
||||
import { pb } from '@/lib/pb';
|
||||
|
||||
export default async function GetPendingCount(): Promise<number> {
|
||||
const { totalItems: count } = await pb.collection(COL_CUSTOMERS).getList(1, 1, {
|
||||
filter: 'status = "pending"',
|
||||
});
|
||||
return count;
|
||||
}
|
3
002_source/cms/src/db/UserMetas/Helloworld.tsx
Normal file
3
002_source/cms/src/db/UserMetas/Helloworld.tsx
Normal file
@@ -0,0 +1,3 @@
|
||||
export function helloCustomer() {
|
||||
return 'Hello from Customers module!';
|
||||
}
|
8
002_source/cms/src/db/UserMetas/Update.tsx
Normal file
8
002_source/cms/src/db/UserMetas/Update.tsx
Normal file
@@ -0,0 +1,8 @@
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_CUSTOMERS } from '@/constants';
|
||||
import type { RecordModel } from 'pocketbase';
|
||||
import type { EditFormProps } from '@/components/dashboard/customer/type.d';
|
||||
|
||||
export async function updateCustomer(id: string, data: Partial<EditFormProps>): Promise<RecordModel> {
|
||||
return pb.collection(COL_CUSTOMERS).update(id, data);
|
||||
}
|
@@ -1,11 +1,12 @@
|
||||
# GUIDELINES
|
||||
|
||||
This folder contains drivers for `UserMeta`/`UserMetas` records using PocketBase:
|
||||
This folder contains drivers for `Customer`/`Customers`(Collection ID: pbc_108570809) records using PocketBase:
|
||||
|
||||
- create (Create.tsx)
|
||||
- read (GetById.tsx)
|
||||
- write (Update.tsx)
|
||||
- count (GetAllCount.tsx)
|
||||
- count (GetAllCount.tsx, GetActiveCount.tsx, GetBlockedCount.tsx, GetPendingCount.tsx)
|
||||
- misc (Helloworld.tsx)
|
||||
- delete (Delete.tsx)
|
||||
- list (GetAll.tsx)
|
||||
|
||||
@@ -15,15 +16,15 @@ the `@` sign refer to `/home/logic/_wsl_workspace/001_github_ws/lettersoup-onlin
|
||||
|
||||
- assume `pb` is located in `@/lib/pb`
|
||||
- no need to handle error in this function, i'll handle it in the caller
|
||||
- type information defined in `@/db/UserMetas/type.d.tsx`
|
||||
- type information defined in `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src/db/Customers/type.d.tsx`
|
||||
|
||||
simple template:
|
||||
|
||||
```typescript
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_USER_METAS } from '@/constants';
|
||||
import { COL_CUSTOMERS } from '@/constants';
|
||||
|
||||
export async function createUserMeta(data: CreateFormProps) {
|
||||
export async function createCustomer(data: CreateFormProps) {
|
||||
// ...content
|
||||
// use direct return of pb.collection (e.g. return pb.collection(xxx))
|
||||
}
|
||||
|
15
002_source/cms/src/db/Users/Create.tsx
Normal file
15
002_source/cms/src/db/Users/Create.tsx
Normal file
@@ -0,0 +1,15 @@
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_USERS } from '@/constants';
|
||||
import type { User } from '@/types/user';
|
||||
|
||||
export async function createUser(userData: Partial<User>): Promise<{
|
||||
data?: User;
|
||||
error?: Error;
|
||||
}> {
|
||||
try {
|
||||
const data = await pb.collection(COL_USERS).create(userData);
|
||||
return { data };
|
||||
} catch (error) {
|
||||
return { error: error as Error };
|
||||
}
|
||||
}
|
14
002_source/cms/src/db/Users/Delete.tsx
Normal file
14
002_source/cms/src/db/Users/Delete.tsx
Normal file
@@ -0,0 +1,14 @@
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_USERS } from '@/constants';
|
||||
|
||||
export async function deleteUserById(id: string): Promise<boolean> {
|
||||
try {
|
||||
await pb.collection(COL_USERS).delete(id);
|
||||
return true;
|
||||
} catch (err) {
|
||||
if (err instanceof Error && err.message.includes('404')) {
|
||||
throw new Error(`User with ID ${id} not found`);
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
9
002_source/cms/src/db/Users/GetActiveCount.tsx
Normal file
9
002_source/cms/src/db/Users/GetActiveCount.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
import { COL_CUSTOMERS } from '@/constants';
|
||||
import { pb } from '@/lib/pb';
|
||||
|
||||
export default async function GetActiveCount(): Promise<number> {
|
||||
const { totalItems: count } = await pb.collection(COL_CUSTOMERS).getList(1, 1, {
|
||||
filter: 'status = "active"',
|
||||
});
|
||||
return count;
|
||||
}
|
7
002_source/cms/src/db/Users/GetAll.tsx
Normal file
7
002_source/cms/src/db/Users/GetAll.tsx
Normal file
@@ -0,0 +1,7 @@
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_CUSTOMERS } from '@/constants';
|
||||
import { RecordModel } from 'pocketbase';
|
||||
|
||||
export async function getAllCustomers(options = {}): Promise<RecordModel[]> {
|
||||
return pb.collection(COL_CUSTOMERS).getFullList(options);
|
||||
}
|
@@ -1,15 +1,7 @@
|
||||
// REQ0006
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_USERS } from '@/constants';
|
||||
|
||||
import { pb } from '@/lib/pb';
|
||||
|
||||
export default async function GetAllCount(): Promise<number> {
|
||||
try {
|
||||
const result = await pb.collection(`users`).getList(1, 9999, { filter: 'email != ""' });
|
||||
const { totalItems: count } = result;
|
||||
return count;
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return -99;
|
||||
}
|
||||
export async function GetAllUsersCount(): Promise<number> {
|
||||
const result = await pb.collection(COL_USERS).getList(1, 1);
|
||||
return result.totalItems;
|
||||
}
|
||||
|
9
002_source/cms/src/db/Users/GetBlockedCount.tsx
Normal file
9
002_source/cms/src/db/Users/GetBlockedCount.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
import { COL_CUSTOMERS } from '@/constants';
|
||||
import { pb } from '@/lib/pb';
|
||||
|
||||
export default async function GetBlockedCount(): Promise<number> {
|
||||
const { totalItems: count } = await pb.collection(COL_CUSTOMERS).getList(1, 1, {
|
||||
filter: 'status = "blocked"',
|
||||
});
|
||||
return count;
|
||||
}
|
15
002_source/cms/src/db/Users/GetById.tsx
Normal file
15
002_source/cms/src/db/Users/GetById.tsx
Normal file
@@ -0,0 +1,15 @@
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_USERS } from '@/constants';
|
||||
import type { User } from '@/types/user';
|
||||
|
||||
export async function getUserById(id: string): Promise<User> {
|
||||
try {
|
||||
const user = await pb.collection(COL_USERS).getOne<User>(id);
|
||||
return user;
|
||||
} catch (err) {
|
||||
if (err instanceof Error && err.message.includes('404')) {
|
||||
throw new Error(`User with ID ${id} not found`);
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
9
002_source/cms/src/db/Users/GetPendingCount.tsx
Normal file
9
002_source/cms/src/db/Users/GetPendingCount.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
import { COL_USERS } from '@/constants';
|
||||
import { pb } from '@/lib/pb';
|
||||
|
||||
export default async function GetPendingCount(): Promise<number> {
|
||||
const { totalItems: count } = await pb.collection(COL_USERS).getList(1, 1, {
|
||||
filter: 'status = "pending"',
|
||||
});
|
||||
return count;
|
||||
}
|
3
002_source/cms/src/db/Users/Helloworld.tsx
Normal file
3
002_source/cms/src/db/Users/Helloworld.tsx
Normal file
@@ -0,0 +1,3 @@
|
||||
export function helloUser() {
|
||||
return 'Hello from Users module!';
|
||||
}
|
21
002_source/cms/src/db/Users/Update.tsx
Normal file
21
002_source/cms/src/db/Users/Update.tsx
Normal file
@@ -0,0 +1,21 @@
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_USERS } from '@/constants';
|
||||
import type { User } from '@/types/user';
|
||||
|
||||
export async function updateUser(
|
||||
id: string,
|
||||
data: Partial<User>
|
||||
): Promise<{
|
||||
data?: User;
|
||||
error?: Error;
|
||||
}> {
|
||||
try {
|
||||
const updatedUser = await pb.collection(COL_USERS).update<User>(id, data);
|
||||
return { data: updatedUser };
|
||||
} catch (error) {
|
||||
if (error instanceof Error && error.message.includes('404')) {
|
||||
return { error: new Error(`User with ID ${id} not found`) };
|
||||
}
|
||||
return { error: error as Error };
|
||||
}
|
||||
}
|
@@ -5,7 +5,8 @@ This folder contains drivers for `User`/`Users` records using PocketBase:
|
||||
- create (Create.tsx)
|
||||
- read (GetById.tsx)
|
||||
- write (Update.tsx)
|
||||
- count (GetAllCount.tsx)
|
||||
- count (GetAllCount.tsx, GetActiveCount.tsx, GetBlockedCount.tsx, GetPendingCount.tsx)
|
||||
- misc (Helloworld.tsx)
|
||||
- delete (Delete.tsx)
|
||||
- list (GetAll.tsx)
|
||||
|
||||
@@ -15,7 +16,7 @@ the `@` sign refer to `/home/logic/_wsl_workspace/001_github_ws/lettersoup-onlin
|
||||
|
||||
- assume `pb` is located in `@/lib/pb`
|
||||
- no need to handle error in this function, i'll handle it in the caller
|
||||
- type information defined in `@/db/Users/type.d.tsx`
|
||||
- type information defined in `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src/db/Users/type.d.tsx`
|
||||
|
||||
simple template:
|
||||
|
||||
|
Reference in New Issue
Block a user