This commit is contained in:
louiscklaw
2025-05-30 01:14:10 +08:00
parent 98bc3fe3ce
commit 834f58bde1
52 changed files with 624 additions and 604 deletions

View File

@@ -511,7 +511,7 @@ model UserCard {
} }
model UserItem { model UserItem {
id Int @id @default(autoincrement()) id String @id @default(uuid())
createdAt DateTime @default(now()) createdAt DateTime @default(now())
updatedAt DateTime @updatedAt updatedAt DateTime @updatedAt
// //

View File

@@ -20,13 +20,13 @@ async function userItem() {
const username = `${firstName.toLowerCase()}-${lastName.toLowerCase()}`; const username = `${firstName.toLowerCase()}-${lastName.toLowerCase()}`;
const alice = await prisma.userItem.upsert({ const alice = await prisma.userItem.upsert({
where: { id: 0 }, where: { id: 'admin_uuid' },
update: {}, update: {},
create: { create: {
name: `${firstName} ${lastName}`, name: `admin test`,
city: '', city: '',
role: '', role: '',
email: `${username}@${SEED_EMAIL_DOMAIN}`, email: `admin@123.com`,
state: '', state: '',
status: '', status: '',
address: '', address: '',
@@ -37,8 +37,8 @@ async function userItem() {
phoneNumber: '', phoneNumber: '',
isVerified: true, isVerified: true,
// //
username, username: 'admin@123.com',
password: await generateHash('Abc1234!'), password: await generateHash('Aa1234567'),
}, },
}); });
@@ -57,16 +57,16 @@ async function userItem() {
} }
const randomFaker = getRandomCJKFaker(); const randomFaker = getRandomCJKFaker();
const alice = await prisma.userItem.upsert({ await prisma.userItem.upsert({
where: { id: i }, where: { id: i.toString() },
update: {}, update: {},
create: { create: {
name: randomFaker.person.fullName(), name: randomFaker.person.fullName(),
city: randomFaker.location.city(), city: randomFaker.location.city(),
role: 'user', role: ROLE[Math.floor(Math.random() * ROLE.length)],
email: randomFaker.internet.email(), email: randomFaker.internet.email(),
state: randomFaker.location.state(), state: randomFaker.location.state(),
status: '', status: STATUS[Math.floor(Math.random() * STATUS.length)],
address: randomFaker.location.streetAddress(), address: randomFaker.location.streetAddress(),
country: randomFaker.location.country(), country: randomFaker.location.country(),
zipCode: randomFaker.location.zipCode(), zipCode: randomFaker.location.zipCode(),
@@ -95,3 +95,32 @@ const userItemSeed = userItem()
}); });
export { userItemSeed }; export { userItemSeed };
const ROLE = [
`CEO`,
`CTO`,
`Project Coordinator`,
`Team Leader`,
`Software Developer`,
`Marketing Strategist`,
`Data Analyst`,
`Product Owner`,
`Graphic Designer`,
`Operations Manager`,
`Customer Support Specialist`,
`Sales Manager`,
`HR Recruiter`,
`Business Consultant`,
`Financial Planner`,
`Network Engineer`,
`Content Creator`,
`Quality Assurance Tester`,
`Public Relations Officer`,
`IT Administrator`,
`Compliance Officer`,
`Event Planner`,
`Legal Counsel`,
`Training Coordinator`,
];
const STATUS = ['active', 'pending', 'banned'];

View File

@@ -7,7 +7,6 @@ import prisma from '../../lib/prisma';
export async function GET(req: NextRequest, res: NextResponse) { export async function GET(req: NextRequest, res: NextResponse) {
try { try {
const users = await prisma.user.findMany(); const users = await prisma.user.findMany();
console.log({ users });
return response({ users }, STATUS.OK); return response({ users }, STATUS.OK);
} catch (error) { } catch (error) {

View File

@@ -0,0 +1,4 @@
###
GET http://localhost:7272/api/helloworld

View File

@@ -24,9 +24,7 @@ export async function GET(req: NextRequest) {
const products = _products(); const products = _products();
// Accept search by name or sku // Accept search by name or sku
const results = products.filter( const results = products.filter(({ name, sku }) => name.toLowerCase().includes(query) || sku?.toLowerCase().includes(query));
({ name, sku }) => name.toLowerCase().includes(query) || sku?.toLowerCase().includes(query)
);
logger('[Product] search-results', results.length); logger('[Product] search-results', results.length);

View File

@@ -1,75 +0,0 @@
// src/app/api/product/createProduct/route.ts
//
// PURPOSE:
// create product to db
//
// RULES:
// T.B.A.
//
import type { NextRequest } from 'next/server';
import { STATUS, response, handleError } from 'src/utils/response';
import prisma from '../../../lib/prisma';
// ----------------------------------------------------------------------
/** **************************************
* POST - Products
*************************************** */
export async function POST(req: NextRequest) {
// logger('[Product] list', products.length);
const { data } = await req.json();
const createForm: CreateProductData = data as unknown as CreateProductData;
console.log({ createForm });
try {
console.log({ data });
await prisma.productItem.create({ data: createForm });
return response({ hello: 'world' }, STATUS.OK);
} catch (error) {
console.log({ hello: 'world', data });
return handleError('Product - Create', error);
}
}
type CreateProductData = {
// id: string;
sku: string;
name: string;
code: string;
price: number;
taxes: number;
tags: string[];
sizes: string[];
publish: string;
gender: string[];
coverUrl: string;
images: string[];
colors: string[];
quantity: number;
category: string;
available: number;
totalSold: number;
description: string;
totalRatings: number;
totalReviews: number;
inventoryType: string;
subDescription: string;
priceSale: number;
newLabel: {
content: string;
enabled: boolean;
};
saleLabel: {
content: string;
enabled: boolean;
};
// ratings: {
// name: string;
// starCount: number;
// reviewCount: number;
// }[];
};

View File

@@ -0,0 +1,53 @@
// src/app/api/user/createUser/route.ts
//
// PURPOSE:
// create user to db
//
// RULES:
// T.B.A.
//
import type { NextRequest } from 'next/server';
import { STATUS, response, handleError } from 'src/utils/response';
import prisma from '../../../lib/prisma';
// ----------------------------------------------------------------------
/**
***************************************
* POST - create User
***************************************
*/
export async function POST(req: NextRequest) {
// logger('[User] list', users.length);
const { data } = await req.json();
const createForm: CreateUserData = data as unknown as CreateUserData;
try {
const user = await prisma.userItem.create({ data: createForm });
return response({ user }, STATUS.OK);
} catch (error) {
return handleError('User - Create', error);
}
}
type CreateUserData = {
name: string;
city: string;
role: string;
email: string;
state: string;
status: string;
address: string;
country: string;
zipCode: string;
company: string;
avatarUrl: string;
phoneNumber: string;
isVerified: boolean;
//
username: string;
password: string;
};

View File

@@ -0,0 +1,4 @@
###
POST http://localhost:7272/api/user/createUser

View File

@@ -1,44 +0,0 @@
// src/app/api/product/deleteProduct/route.ts
//
// PURPOSE:
// delete product from db by id
//
// RULES:
// T.B.A.
import type { NextRequest } from 'next/server';
import { logger } from 'src/utils/logger';
import { STATUS, response, handleError } from 'src/utils/response';
import prisma from '../../../lib/prisma';
// ----------------------------------------------------------------------
/** **************************************
* handle Delete Products
*************************************** */
export async function DELETE(req: NextRequest) {
try {
const { searchParams } = req.nextUrl;
// RULES: productId must exist
const productId = searchParams.get('productId');
if (!productId) {
return response({ message: 'Product ID is required!' }, STATUS.BAD_REQUEST);
}
// NOTE: productId confirmed exist, run below
const product = await prisma.productItem.delete({ where: { id: productId } });
if (!product) {
return response({ message: 'Product not found!' }, STATUS.NOT_FOUND);
}
logger('[Product] details', product.id);
return response({ product }, STATUS.OK);
} catch (error) {
return handleError('Product - Get details', error);
}
}

View File

@@ -1,3 +0,0 @@
###
DELETE http://localhost:7272/api/product/deleteProduct?productId=e99f09a7-dd88-49d5-b1c8-1daf80c2d7b06

View File

@@ -0,0 +1,47 @@
// src/app/api/product/deleteUser/route.ts
//
// PURPOSE:
// delete product from db by id
//
// RULES:
// T.B.A.
import type { NextRequest } from 'next/server';
import { logger } from 'src/utils/logger';
import { STATUS, response, handleError } from 'src/utils/response';
import prisma from '../../../lib/prisma';
// ----------------------------------------------------------------------
/** **************************************
* handle Delete Users
*************************************** */
export async function DELETE(req: NextRequest) {
try {
const { searchParams } = req.nextUrl;
// RULES: userId must exist
const userId = searchParams.get('userId');
if (!userId) {
return response({ message: 'User ID is required!' }, STATUS.BAD_REQUEST);
}
// NOTE: userId confirmed exist, run below
const user = await prisma.userItem.delete({
//
where: { id: userId },
});
if (!user) {
return response({ message: 'User not found!' }, STATUS.NOT_FOUND);
}
logger('[User] details', user.id);
return response({ user }, STATUS.OK);
} catch (error) {
return handleError('User - Get details', error);
}
}

View File

@@ -0,0 +1,3 @@
###
DELETE http://localhost:7272/api/user/deleteUser?userId=3f431e6f-ad05-4d60-9c25-6a7e92a954ad

View File

@@ -1,7 +1,7 @@
// src/app/api/product/details/route.ts // src/app/api/product/details/route.ts
// //
// PURPOSE: // PURPOSE:
// save product to db by id // read user from db by id
// //
// RULES: // RULES:
// T.B.A. // T.B.A.
@@ -16,31 +16,31 @@ import prisma from '../../../lib/prisma';
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
/** ************************************** /** **************************************
* GET Product detail * GET User detail
*************************************** */ *************************************** */
export async function GET(req: NextRequest) { export async function GET(req: NextRequest) {
try { try {
const { searchParams } = req.nextUrl; const { searchParams } = req.nextUrl;
// RULES: productId must exist // RULES: userId must exist
const productId = searchParams.get('productId'); const userId = searchParams.get('userId');
if (!productId) { if (!userId) {
return response({ message: 'Product ID is required!' }, STATUS.BAD_REQUEST); return response({ message: 'userId is required!' }, STATUS.BAD_REQUEST);
} }
// NOTE: productId confirmed exist, run below // NOTE: userId confirmed exist, run below
const product = await prisma.productItem.findFirst({ const user = await prisma.userItem.findFirst({
include: { reviews: true }, // include: { reviews: true },
where: { id: productId }, where: { id: userId },
}); });
if (!product) { if (!user) {
return response({ message: 'Product not found!' }, STATUS.NOT_FOUND); return response({ message: 'User not found!' }, STATUS.NOT_FOUND);
} }
logger('[Product] details', product.id); logger('[User] details', user.id);
return response({ product }, STATUS.OK); return response({ user }, STATUS.OK);
} catch (error) { } catch (error) {
return handleError('Product - Get details', error); return handleError('Product - Get details', error);
} }

View File

@@ -0,0 +1,4 @@
###
GET http://localhost:7272/api/user/details?userId=1165ce3a-29b8-4e1a-9148-1ae08d7e8e01

View File

@@ -1,4 +1,3 @@
### ###
GET http://localhost:7272/api/user/list GET http://localhost:7272/api/user/list

View File

@@ -19,54 +19,40 @@ import prisma from '../../../lib/prisma';
*************************************** */ *************************************** */
export async function POST(req: NextRequest) { export async function POST(req: NextRequest) {
// logger('[Product] list', products.length); // logger('[Product] list', products.length);
const { searchParams } = req.nextUrl;
const userId = searchParams.get('userId');
// RULES: userId must exist
if (!userId) {
return response({ message: 'Product ID is required!' }, STATUS.BAD_REQUEST);
}
const { data } = await req.json(); const { data } = await req.json();
try { try {
const products = await prisma.productItem.updateMany({ const user = await prisma.userItem.updateMany({
where: { id: userId },
data: { data: {
status: data.status,
avatarUrl: data.avatarUrl,
isVerified: data.isVerified,
name: data.name, name: data.name,
sku: data.sku, email: data.email,
code: data.code, phoneNumber: data.phoneNumber,
price: data.price, country: data.country,
taxes: data.taxes, state: data.state,
tags: data.tags, city: data.city,
sizes: data.sizes, address: data.address,
publish: data.publish, zipCode: data.zipCode,
gender: data.gender, company: data.company,
coverUrl: data.coverUrl, role: data.role,
images: data.images,
colors: data.colors,
quantity: data.quantity,
category: data.category,
available: data.available,
totalSold: data.totalSold,
description: data.description,
totalRatings: data.totalRatings,
totalReviews: data.totalReviews,
inventoryType: data.inventoryType,
subDescription: data.subDescription,
priceSale: data.priceSale,
// //
newLabel: { username: data.username,
content: data.newLabel?.content || '', password: data.password,
enabled: data.newLabel?.enabled ?? false,
},
saleLabel: {
content: data.saleLabel?.content || '',
enabled: data.saleLabel?.enabled ?? false,
},
ratings: {
set: data.ratings.map((rating: { name: string; starCount: number; reviewCount: number }) => ({
name: rating.name,
starCount: rating.starCount,
reviewCount: rating.reviewCount,
})),
},
}, },
where: { id: data.id },
}); });
return response({ hello: 'world', data }, STATUS.OK); return response({ user }, STATUS.OK);
} catch (error) { } catch (error) {
console.log({ hello: 'world', data }); console.log({ hello: 'world', data });
return handleError('Product - Get list', error); return handleError('Product - Get list', error);

View File

@@ -0,0 +1,3 @@
###
POST http://localhost:7272/api/user/list

View File

@@ -10,7 +10,9 @@ const config = {
printWidth: 100, printWidth: 100,
singleQuote: true, singleQuote: true,
trailingComma: 'es5', trailingComma: 'es5',
plugins: ['@ianvs/prettier-plugin-sort-imports'], plugins: [
// '@ianvs/prettier-plugin-sort-imports'
],
}; };
export default config; export default config;

View File

@@ -15,15 +15,14 @@ const swrOptions: SWRConfiguration = {
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
type UserData = { type UsersData = {
users: IUserItem[]; users: IUserItem[];
}; };
export function useGetUsers() { export function useGetUsers() {
// const url = endpoints.user.list;
const url = `http://localhost:7272/api/user/list`; const url = `http://localhost:7272/api/user/list`;
const { data, isLoading, error, isValidating, mutate } = useSWR<UserData>( const { data, isLoading, error, isValidating, mutate } = useSWR<UsersData>(
url, url,
fetcher, fetcher,
swrOptions swrOptions
@@ -46,23 +45,23 @@ export function useGetUsers() {
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
type ProductData = { type UserData = {
product: IProductItem; user: IUserItem;
}; };
export function useGetProduct(productId: string) { export function useGetUser(userId: string) {
const url = productId ? [endpoints.product.details, { params: { productId } }] : ''; const url = userId ? [endpoints.user.details, { params: { userId } }] : '';
const { data, isLoading, error, isValidating } = useSWR<ProductData>(url, fetcher, swrOptions); const { data, isLoading, error, isValidating } = useSWR<UserData>(url, fetcher, swrOptions);
const memoizedValue = useMemo( const memoizedValue = useMemo(
() => ({ () => ({
product: data?.product, user: data?.user,
productLoading: isLoading, userLoading: isLoading,
productError: error, userError: error,
productValidating: isValidating, userValidating: isValidating,
}), }),
[data?.product, error, isLoading, isValidating] [data?.user, error, isLoading, isValidating]
); );
return memoizedValue; return memoizedValue;
@@ -98,59 +97,42 @@ export function useSearchProducts(query: string) {
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
type SaveProductData = { type SaveUserData = {
// id: string;
sku: string;
name: string; name: string;
code: string; city: string;
price: number | null; role: string;
taxes: number | null; email: string;
tags: string[]; state: string;
sizes: string[]; status: string;
// publish: string; address: string;
gender: string[]; country: string;
// coverUrl: string; zipCode: string;
images: (string | File)[]; company: string;
colors: string[]; avatarUrl: string;
quantity: number | null; phoneNumber: string;
category: string; isVerified: boolean;
// available: number; //
// totalSold: number; username: string;
description: string; password: string;
// totalRatings: number;
// totalReviews: number;
// inventoryType: string;
subDescription: string;
priceSale: number | null;
newLabel: {
content: string;
enabled: boolean;
};
saleLabel: {
content: string;
enabled: boolean;
};
// ratings: {
// name: string;
// starCount: number;
// reviewCount: number;
// }[];
}; };
export async function saveProduct(productId: string, saveProductData: SaveProductData) { export async function saveUser(userId: string, saveUserData: SaveUserData) {
console.log('save product ?'); // const url = userId ? [endpoints.user.details, { params: { userId } }] : '';
// const url = productId ? [endpoints.product.details, { params: { productId } }] : '';
const res = await axiosInstance.post('http://localhost:7272/api/product/saveProduct', { const res = await axiosInstance.post(
data: saveProductData, //
}); `http://localhost:7272/api/user/saveUser?userId=${userId}`,
{
data: saveUserData,
}
);
return res; return res;
} }
export async function uploadProductImage(saveProductData: SaveProductData) { export async function uploadUserImage(saveUserData: SaveUserData) {
console.log('save product ?'); console.log('uploadUserImage ?');
// const url = productId ? [endpoints.product.details, { params: { productId } }] : ''; // const url = userId ? [endpoints.user.details, { params: { userId } }] : '';
const res = await axiosInstance.get('http://localhost:7272/api/product/helloworld'); const res = await axiosInstance.get('http://localhost:7272/api/product/helloworld');
@@ -159,51 +141,31 @@ export async function uploadProductImage(saveProductData: SaveProductData) {
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
type CreateProductData = { type CreateUserData = {
// id: string;
sku: string;
name: string; name: string;
code: string; city: string;
price: number | null; role: string;
taxes: number | null; email: string;
tags: string[]; state: string;
sizes: string[]; status: string;
publish: string; address: string;
gender: string[]; country: string;
coverUrl: string; zipCode: string;
images: (string | File)[]; company: string;
colors: string[]; avatarUrl: string;
quantity: number | null; phoneNumber: string;
category: string; isVerified: boolean;
available: number; //
totalSold: number; username: string;
description: string; password: string;
totalRatings: number;
totalReviews: number;
inventoryType: string;
subDescription: string;
priceSale: number | null;
newLabel: {
content: string;
enabled: boolean;
};
saleLabel: {
content: string;
enabled: boolean;
};
// ratings: {
// name: string;
// starCount: number;
// reviewCount: number;
// }[];
}; };
export async function createProduct(createProductData: CreateProductData) { export async function createUser(createUserData: CreateUserData) {
console.log('create product ?'); console.log('create product ?');
// const url = productId ? [endpoints.product.details, { params: { productId } }] : ''; // const url = productId ? [endpoints.product.details, { params: { productId } }] : '';
const res = await axiosInstance.post('http://localhost:7272/api/product/createProduct', { const res = await axiosInstance.post('http://localhost:7272/api/user/createUser', {
data: createProductData, data: createUserData,
}); });
return res; return res;
@@ -211,21 +173,20 @@ export async function createProduct(createProductData: CreateProductData) {
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
type DeleteProductResponse = { type DeleteUserResponse = {
success: boolean; success: boolean;
message?: string; message?: string;
}; };
export async function deleteUser(productId: string): Promise<DeleteProductResponse> { export async function deleteUser(userId: string): Promise<DeleteUserResponse> {
const url = `http://localhost:7272/api/product/deleteProduct?productId=${productId}`; const url = `http://localhost:7272/api/user/deleteUser?userId=${userId}`;
try { try {
const res = await axiosInstance.delete(url); const res = await axiosInstance.delete(url);
console.log({ res });
return { return {
success: true, success: true,
message: 'Product deleted successfully', message: 'User deleted successfully',
}; };
} catch (error) { } catch (error) {
return { return {

View File

@@ -26,11 +26,7 @@ export function NavSectionMini({
const cssVars = { ...navSectionCssVars.mini(theme), ...overridesVars }; const cssVars = { ...navSectionCssVars.mini(theme), ...overridesVars };
return ( return (
<Nav <Nav className={mergeClasses([navSectionClasses.mini, className])} sx={[{ ...cssVars }, ...(Array.isArray(sx) ? sx : [sx])]} {...other}>
className={mergeClasses([navSectionClasses.mini, className])}
sx={[{ ...cssVars }, ...(Array.isArray(sx) ? sx : [sx])]}
{...other}
>
<NavUl sx={{ flex: '1 1 auto', gap: 'var(--nav-item-gap)' }}> <NavUl sx={{ flex: '1 1 auto', gap: 'var(--nav-item-gap)' }}>
{data.map((group) => ( {data.map((group) => (
<Group <Group
@@ -50,14 +46,7 @@ export function NavSectionMini({
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
function Group({ function Group({ items, render, cssVars, slotProps, checkPermissions, enabledRootRedirect }: NavGroupProps) {
items,
render,
cssVars,
slotProps,
checkPermissions,
enabledRootRedirect,
}: NavGroupProps) {
return ( return (
<NavLi> <NavLi>
<NavUl sx={{ gap: 'var(--nav-item-gap)' }}> <NavUl sx={{ gap: 'var(--nav-item-gap)' }}>

View File

@@ -6,6 +6,7 @@ import { Nav, NavLi, NavSubheader, NavUl } from '../components';
import { navSectionClasses, navSectionCssVars } from '../styles'; import { navSectionClasses, navSectionCssVars } from '../styles';
import type { NavGroupProps, NavSectionProps } from '../types'; import type { NavGroupProps, NavSectionProps } from '../types';
import { NavList } from './nav-list'; import { NavList } from './nav-list';
import { useTranslation } from 'react-i18next';
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@@ -25,11 +26,7 @@ export function NavSectionVertical({
const cssVars = { ...navSectionCssVars.vertical(theme), ...overridesVars }; const cssVars = { ...navSectionCssVars.vertical(theme), ...overridesVars };
return ( return (
<Nav <Nav className={mergeClasses([navSectionClasses.vertical, className])} sx={[{ ...cssVars }, ...(Array.isArray(sx) ? sx : [sx])]} {...other}>
className={mergeClasses([navSectionClasses.vertical, className])}
sx={[{ ...cssVars }, ...(Array.isArray(sx) ? sx : [sx])]}
{...other}
>
<NavUl sx={{ flex: '1 1 auto', gap: 'var(--nav-item-gap)' }}> <NavUl sx={{ flex: '1 1 auto', gap: 'var(--nav-item-gap)' }}>
{data.map((group) => ( {data.map((group) => (
<Group <Group
@@ -49,15 +46,9 @@ export function NavSectionVertical({
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
function Group({ function Group({ items, render, subheader, slotProps, checkPermissions, enabledRootRedirect }: NavGroupProps) {
items,
render,
subheader,
slotProps,
checkPermissions,
enabledRootRedirect,
}: NavGroupProps) {
const groupOpen = useBoolean(true); const groupOpen = useBoolean(true);
const { t } = useTranslation();
const renderContent = () => ( const renderContent = () => (
<NavUl sx={{ gap: 'var(--nav-item-gap)' }}> <NavUl sx={{ gap: 'var(--nav-item-gap)' }}>
@@ -79,13 +70,8 @@ function Group({
<NavLi> <NavLi>
{subheader ? ( {subheader ? (
<> <>
<NavSubheader <NavSubheader data-title={subheader} open={groupOpen.value} onClick={groupOpen.onToggle} sx={slotProps?.subheader}>
data-title={subheader} {t(subheader)}
open={groupOpen.value}
onClick={groupOpen.onToggle}
sx={slotProps?.subheader}
>
{subheader}
</NavSubheader> </NavSubheader>
<Collapse in={groupOpen.value}>{renderContent()}</Collapse> <Collapse in={groupOpen.value}>{renderContent()}</Collapse>
</> </>

View File

@@ -11,18 +11,12 @@ import { uploadClasses } from './classes';
import { RejectionFiles } from './components/rejection-files'; import { RejectionFiles } from './components/rejection-files';
import type { UploadProps } from './types'; import type { UploadProps } from './types';
import { useTranslation } from 'react-i18next';
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
export function UploadAvatar({ export function UploadAvatar({ sx, error, value, disabled, helperText, className, ...other }: UploadProps) {
sx, const { t } = useTranslation();
error,
value,
disabled,
helperText,
className,
...other
}: UploadProps) {
const { getRootProps, getInputProps, isDragActive, isDragReject, fileRejections } = useDropzone({ const { getRootProps, getInputProps, isDragActive, isDragReject, fileRejections } = useDropzone({
multiple: false, multiple: false,
disabled, disabled,
@@ -44,10 +38,7 @@ export function UploadAvatar({
} }
}, [value]); }, [value]);
const renderPreview = () => const renderPreview = () => hasFile && <Image alt="Avatar" src={preview} sx={{ width: 1, height: 1, borderRadius: '50%' }} />;
hasFile && (
<Image alt="Avatar" src={preview} sx={{ width: 1, height: 1, borderRadius: '50%' }} />
);
const renderPlaceholder = () => ( const renderPlaceholder = () => (
<Box <Box
@@ -85,7 +76,7 @@ export function UploadAvatar({
> >
<Iconify icon="solar:camera-add-bold" width={32} /> <Iconify icon="solar:camera-add-bold" width={32} />
<Typography variant="caption">{hasFile ? 'Update photo' : 'Upload photo'}</Typography> <Typography variant="caption">{hasFile ? t('Update photo') : t('Update photo')}</Typography>
</Box> </Box>
); );

View File

@@ -35,9 +35,7 @@ const flattenNavItems = (navItems: NavItem[], parentGroup?: string): OutputItem[
}; };
export function flattenNavSections(navSections: NavSectionProps['data']): OutputItem[] { export function flattenNavSections(navSections: NavSectionProps['data']): OutputItem[] {
return navSections.flatMap((navSection) => return navSections.flatMap((navSection) => flattenNavItems(navSection.items, navSection.subheader));
flattenNavItems(navSection.items, navSection.subheader)
);
} }
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@@ -50,7 +48,5 @@ type ApplyFilterProps = {
export function applyFilter({ inputData, query }: ApplyFilterProps): OutputItem[] { export function applyFilter({ inputData, query }: ApplyFilterProps): OutputItem[] {
if (!query) return inputData; if (!query) return inputData;
return inputData.filter(({ title, path, group }) => return inputData.filter(({ title, path, group }) => [title, path, group].some((field) => field?.toLowerCase().includes(query.toLowerCase())));
[title, path, group].some((field) => field?.toLowerCase().includes(query.toLowerCase()))
);
} }

View File

@@ -50,13 +50,7 @@ export type DashboardLayoutProps = LayoutBaseProps & {
}; };
}; };
export function DashboardLayout({ export function DashboardLayout({ sx, cssVars, children, slotProps, layoutQuery = 'lg' }: DashboardLayoutProps) {
sx,
cssVars,
children,
slotProps,
layoutQuery = 'lg',
}: DashboardLayoutProps) {
const theme = useTheme(); const theme = useTheme();
const { user } = useMockedUser(); const { user } = useMockedUser();
@@ -73,8 +67,7 @@ export function DashboardLayout({
const isNavHorizontal = settings.state.navLayout === 'horizontal'; const isNavHorizontal = settings.state.navLayout === 'horizontal';
const isNavVertical = isNavMini || settings.state.navLayout === 'vertical'; const isNavVertical = isNavMini || settings.state.navLayout === 'vertical';
const canDisplayItemByRole = (allowedRoles: NavItemProps['allowedRoles']): boolean => const canDisplayItemByRole = (allowedRoles: NavItemProps['allowedRoles']): boolean => !allowedRoles?.includes(user?.role);
!allowedRoles?.includes(user?.role);
const renderHeader = () => { const renderHeader = () => {
const headerSlotProps: HeaderSectionProps['slotProps'] = { const headerSlotProps: HeaderSectionProps['slotProps'] = {
@@ -98,27 +91,13 @@ export function DashboardLayout({
</Alert> </Alert>
), ),
bottomArea: isNavHorizontal ? ( bottomArea: isNavHorizontal ? (
<NavHorizontal <NavHorizontal data={navData} layoutQuery={layoutQuery} cssVars={navVars.section} checkPermissions={canDisplayItemByRole} />
data={navData}
layoutQuery={layoutQuery}
cssVars={navVars.section}
checkPermissions={canDisplayItemByRole}
/>
) : null, ) : null,
leftArea: ( leftArea: (
<> <>
{/** @slot Nav mobile */} {/** @slot Nav mobile */}
<MenuButton <MenuButton onClick={onOpen} sx={{ mr: 1, ml: -1, [theme.breakpoints.up(layoutQuery)]: { display: 'none' } }} />
onClick={onOpen} <NavMobile data={navData} open={open} onClose={onClose} cssVars={navVars.section} checkPermissions={canDisplayItemByRole} />
sx={{ mr: 1, ml: -1, [theme.breakpoints.up(layoutQuery)]: { display: 'none' } }}
/>
<NavMobile
data={navData}
open={open}
onClose={onClose}
cssVars={navVars.section}
checkPermissions={canDisplayItemByRole}
/>
{/** @slot Logo */} {/** @slot Logo */}
{isNavHorizontal && ( {isNavHorizontal && (
@@ -131,15 +110,10 @@ export function DashboardLayout({
)} )}
{/** @slot Divider */} {/** @slot Divider */}
{isNavHorizontal && ( {isNavHorizontal && <VerticalDivider sx={{ [theme.breakpoints.up(layoutQuery)]: { display: 'flex' } }} />}
<VerticalDivider sx={{ [theme.breakpoints.up(layoutQuery)]: { display: 'flex' } }} />
)}
{/** @slot Workspace popover */} {/** @slot Workspace popover */}
<WorkspacesPopover <WorkspacesPopover data={_workspaces} sx={{ ...(isNavHorizontal && { color: 'var(--layout-nav-text-primary-color)' }) }} />
data={_workspaces}
sx={{ ...(isNavHorizontal && { color: 'var(--layout-nav-text-primary-color)' }) }}
/>
</> </>
), ),
rightArea: ( rightArea: (
@@ -184,12 +158,7 @@ export function DashboardLayout({
layoutQuery={layoutQuery} layoutQuery={layoutQuery}
cssVars={navVars.section} cssVars={navVars.section}
checkPermissions={canDisplayItemByRole} checkPermissions={canDisplayItemByRole}
onToggleNav={() => onToggleNav={() => settings.setField('navLayout', settings.state.navLayout === 'vertical' ? 'mini' : 'vertical')}
settings.setField(
'navLayout',
settings.state.navLayout === 'vertical' ? 'mini' : 'vertical'
)
}
/> />
); );

View File

@@ -23,18 +23,7 @@ export type NavVerticalProps = React.ComponentProps<'div'> &
}; };
}; };
export function NavVertical({ export function NavVertical({ sx, data, slots, cssVars, className, isNavMini, onToggleNav, checkPermissions, layoutQuery = 'md', ...other }: NavVerticalProps) {
sx,
data,
slots,
cssVars,
className,
isNavMini,
onToggleNav,
checkPermissions,
layoutQuery = 'md',
...other
}: NavVerticalProps) {
const renderNavVertical = () => ( const renderNavVertical = () => (
<> <>
{slots?.topArea ?? ( {slots?.topArea ?? (
@@ -44,12 +33,7 @@ export function NavVertical({
)} )}
<Scrollbar fillContent> <Scrollbar fillContent>
<NavSectionVertical <NavSectionVertical data={data} cssVars={cssVars} checkPermissions={checkPermissions} sx={{ px: 2, flex: '1 1 auto' }} />
data={data}
cssVars={cssVars}
checkPermissions={checkPermissions}
sx={{ px: 2, flex: '1 1 auto' }}
/>
{slots?.bottomArea ?? <NavUpgrade />} {slots?.bottomArea ?? <NavUpgrade />}
</Scrollbar> </Scrollbar>
@@ -110,22 +94,20 @@ export function NavVertical({
const NavRoot = styled('div', { const NavRoot = styled('div', {
shouldForwardProp: (prop: string) => !['isNavMini', 'layoutQuery', 'sx'].includes(prop), shouldForwardProp: (prop: string) => !['isNavMini', 'layoutQuery', 'sx'].includes(prop),
})<Pick<NavVerticalProps, 'isNavMini' | 'layoutQuery'>>( })<Pick<NavVerticalProps, 'isNavMini' | 'layoutQuery'>>(({ isNavMini, layoutQuery = 'md', theme }) => ({
({ isNavMini, layoutQuery = 'md', theme }) => ({ top: 0,
top: 0, left: 0,
left: 0, height: '100%',
height: '100%', display: 'none',
display: 'none', position: 'fixed',
position: 'fixed', flexDirection: 'column',
flexDirection: 'column', zIndex: 'var(--layout-nav-zIndex)',
zIndex: 'var(--layout-nav-zIndex)', backgroundColor: 'var(--layout-nav-bg)',
backgroundColor: 'var(--layout-nav-bg)', width: isNavMini ? 'var(--layout-nav-mini-width)' : 'var(--layout-nav-vertical-width)',
width: isNavMini ? 'var(--layout-nav-mini-width)' : 'var(--layout-nav-vertical-width)', borderRight: `1px solid var(--layout-nav-border-color, ${varAlpha(theme.vars.palette.grey['500Channel'], 0.12)})`,
borderRight: `1px solid var(--layout-nav-border-color, ${varAlpha(theme.vars.palette.grey['500Channel'], 0.12)})`, transition: theme.transitions.create(['width'], {
transition: theme.transitions.create(['width'], { easing: 'var(--layout-transition-easing)',
easing: 'var(--layout-transition-easing)', duration: 'var(--layout-transition-duration)',
duration: 'var(--layout-transition-duration)', }),
}), [theme.breakpoints.up(layoutQuery)]: { display: 'flex' },
[theme.breakpoints.up(layoutQuery)]: { display: 'flex' }, }));
})
);

View File

@@ -55,11 +55,7 @@ const shouldForwardProp = (prop: string) => !['open', 'active', 'variant', 'sx']
/** /**
* @slot root * @slot root
*/ */
const ItemRoot = styled(ButtonBase, { shouldForwardProp })<StyledState>(({ const ItemRoot = styled(ButtonBase, { shouldForwardProp })<StyledState>(({ active, open, theme }) => {
active,
open,
theme,
}) => {
const dotTransitions: Record<'in' | 'out', CSSObject> = { const dotTransitions: Record<'in' | 'out', CSSObject> = {
in: { opacity: 0, scale: 0 }, in: { opacity: 0, scale: 0 },
out: { opacity: 1, scale: 1 }, out: { opacity: 1, scale: 1 },

View File

@@ -106,12 +106,7 @@ function NavSubList({ data, subheader, sx, ...other }: NavSubListProps) {
</NavLi> </NavLi>
) : ( ) : (
<NavLi key={item.title} sx={{ mt: 0.75 }}> <NavLi key={item.title} sx={{ mt: 0.75 }}>
<NavItem <NavItem subItem title={item.title} path={item.path} active={isEqualPath(item.path, pathname)} />
subItem
title={item.title}
path={item.path}
active={isEqualPath(item.path, pathname)}
/>
</NavLi> </NavLi>
) )
)} )}

View File

@@ -71,5 +71,55 @@
"Rejected": "已反對", "Rejected": "已反對",
"Quick update": "快速更新", "Quick update": "快速更新",
"Address": "地址", "Address": "地址",
"Followers": "追隨者",
"Follower": "追隨者",
"Following": "正在追隨",
"Friends": "朋友圈",
"Gallery": "相集",
"About": "關於用戶",
"Social": "社交媒體",
"Post": "發帖",
"Image/Video": "相/視頻",
"Streaming": "直播",
"Delete": "清除",
"Cancel": "取消",
"Overview": "概覽",
"Management": "管理",
"Quick Edit": "簡易編輯",
"Choose a country": "選擇一個城市",
"Create user": "新用戶",
"State/region": "State/region",
"Misc": "雜項",
"Email verified": "電郵核實",
"Update photo": "上傳相片",
"Create a new user": "創建新用戶",
"Allowed": "Allowed",
"max size of": "max size of",
"Disabling this will automatically send the user a verification email": "Disabling this will automatically send the user a verification email",
"Full name": "Full name",
"Email address": "Email address",
"Country": "Country",
"City": "City",
"Zip/code": "Zip/code",
"Update success": "更新完成",
"Create success": "創建完成",
"Save changes": "儲存變更",
"Product List": "產品列表",
"View": "詳細資料",
"Completed": "已完成",
"Cancelled": "已取消",
"Refunded": "已退款",
"Date ": "日期",
"Order ": "訂單",
"Customer ": "客戶",
"Items ": "項目",
"Start date ": "開始日期",
"End date ": "結束日期",
"Search customer or order number... ": "搜尋客戶或訂單號碼...",
"Print ": "列印",
"Import ": "匯入",
"Export ": "匯出",
"Product not found!": "產品未找到!",
"Back to list": "返回列表",
"hello": "world" "hello": "world"
} }

View File

@@ -13,7 +13,6 @@ export default function Page() {
const { id = '' } = useParams(); const { id = '' } = useParams();
const { product } = useGetProduct(id); const { product } = useGetProduct(id);
console.log({ id });
return ( return (
<> <>

View File

@@ -1,7 +1,8 @@
import { _userList } from 'src/_mock/_user'; // import { _userList } from 'src/_mock/_user';
import { CONFIG } from 'src/global-config'; import { CONFIG } from 'src/global-config';
import { useParams } from 'src/routes/hooks'; import { useParams } from 'src/routes/hooks';
import { UserEditView } from 'src/sections/user/view'; import { UserEditView } from 'src/sections/user/view';
import { useGetUser } from 'src/actions/user';
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@@ -10,13 +11,15 @@ const metadata = { title: `User edit | Dashboard - ${CONFIG.appName}` };
export default function Page() { export default function Page() {
const { id = '' } = useParams(); const { id = '' } = useParams();
const currentUser = _userList.find((user) => user.id === id); // TODO: remove me
// const currentUser = _userList.find((user) => user.id === id);
const { user } = useGetUser(id);
return ( return (
<> <>
<title>{metadata.title}</title> <title>{metadata.title}</title>
<UserEditView user={currentUser} /> <UserEditView user={user} />
</> </>
); );
} }

View File

@@ -63,9 +63,7 @@ export function AccountNotifications({ sx, ...other }: CardProps) {
}); });
const getSelected = (selectedItems: string[], item: string) => const getSelected = (selectedItems: string[], item: string) =>
selectedItems.includes(item) selectedItems.includes(item) ? selectedItems.filter((value) => value !== item) : [...selectedItems, item];
? selectedItems.filter((value) => value !== item)
: [...selectedItems, item];
return ( return (
<Form methods={methods} onSubmit={onSubmit}> <Form methods={methods} onSubmit={onSubmit}>

View File

@@ -49,23 +49,15 @@ import { InvoiceAnalytic } from '../invoice-analytic';
import { InvoiceTableRow } from '../invoice-table-row'; import { InvoiceTableRow } from '../invoice-table-row';
import { InvoiceTableToolbar } from '../invoice-table-toolbar'; import { InvoiceTableToolbar } from '../invoice-table-toolbar';
import { InvoiceTableFiltersResult } from '../invoice-table-filters-result'; import { InvoiceTableFiltersResult } from '../invoice-table-filters-result';
import { useTranslation } from 'react-i18next';
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
const TABLE_HEAD: TableHeadCellProps[] = [
{ id: 'invoiceNumber', label: 'Customer' },
{ id: 'createDate', label: 'Create' },
{ id: 'dueDate', label: 'Due' },
{ id: 'price', label: 'Amount' },
{ id: 'sent', label: 'Sent', align: 'center' },
{ id: 'status', label: 'Status' },
{ id: '' },
];
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
export function InvoiceListView() { export function InvoiceListView() {
const theme = useTheme(); const theme = useTheme();
const { t } = useTranslation();
const table = useTable({ defaultOrderBy: 'createDate' }); const table = useTable({ defaultOrderBy: 'createDate' });
@@ -73,6 +65,16 @@ export function InvoiceListView() {
const [tableData, setTableData] = useState<IInvoice[]>(_invoices); const [tableData, setTableData] = useState<IInvoice[]>(_invoices);
const TABLE_HEAD: TableHeadCellProps[] = [
{ id: 'invoiceNumber', label: t('Customer') },
{ id: 'createDate', label: t('Create') },
{ id: 'dueDate', label: t('Due') },
{ id: 'price', label: t('Amount') },
{ id: 'sent', label: t('Sent'), align: 'center' },
{ id: 'status', label: t('Status') },
{ id: '' },
];
const filters = useSetState<IInvoiceTableFilters>({ const filters = useSetState<IInvoiceTableFilters>({
name: '', name: '',
service: [], service: [],

View File

@@ -1,3 +1,4 @@
// src/sections/order/view/order-list-view.tsx
import type { IOrderItem } from 'src/types/order'; import type { IOrderItem } from 'src/types/order';
import { useBoolean, usePopover } from 'minimal-shared/hooks'; import { useBoolean, usePopover } from 'minimal-shared/hooks';
@@ -26,6 +27,7 @@ import { Label } from 'src/components/label';
import { Iconify } from 'src/components/iconify'; import { Iconify } from 'src/components/iconify';
import { ConfirmDialog } from 'src/components/custom-dialog'; import { ConfirmDialog } from 'src/components/custom-dialog';
import { CustomPopover } from 'src/components/custom-popover'; import { CustomPopover } from 'src/components/custom-popover';
import { useTranslation } from 'react-i18next';
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@@ -41,6 +43,7 @@ export function OrderTableRow({ row, selected, onSelectRow, onDeleteRow, details
const confirmDialog = useBoolean(); const confirmDialog = useBoolean();
const menuActions = usePopover(); const menuActions = usePopover();
const collapseRow = useBoolean(); const collapseRow = useBoolean();
const { t } = useTranslation();
const renderPrimaryRow = () => ( const renderPrimaryRow = () => (
<TableRow hover selected={selected}> <TableRow hover selected={selected}>
@@ -195,13 +198,13 @@ export function OrderTableRow({ row, selected, onSelectRow, onDeleteRow, details
sx={{ color: 'error.main' }} sx={{ color: 'error.main' }}
> >
<Iconify icon="solar:trash-bin-trash-bold" /> <Iconify icon="solar:trash-bin-trash-bold" />
Delete {t('Delete')}
</MenuItem> </MenuItem>
<li> <li>
<MenuItem component={RouterLink} href={detailsHref} onClick={() => menuActions.onClose()}> <MenuItem component={RouterLink} href={detailsHref} onClick={() => menuActions.onClose()}>
<Iconify icon="solar:eye-bold" /> <Iconify icon="solar:eye-bold" />
View {t('View')}
</MenuItem> </MenuItem>
</li> </li>
</MenuList> </MenuList>

View File

@@ -16,6 +16,7 @@ import { formHelperTextClasses } from '@mui/material/FormHelperText';
import { Iconify } from 'src/components/iconify'; import { Iconify } from 'src/components/iconify';
import { CustomPopover } from 'src/components/custom-popover'; import { CustomPopover } from 'src/components/custom-popover';
import { useTranslation } from 'react-i18next';
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@@ -26,6 +27,7 @@ type Props = {
}; };
export function OrderTableToolbar({ filters, onResetPage, dateError }: Props) { export function OrderTableToolbar({ filters, onResetPage, dateError }: Props) {
const { t } = useTranslation();
const menuActions = usePopover(); const menuActions = usePopover();
const { state: currentFilters, setState: updateFilters } = filters; const { state: currentFilters, setState: updateFilters } = filters;
@@ -64,17 +66,17 @@ export function OrderTableToolbar({ filters, onResetPage, dateError }: Props) {
<MenuList> <MenuList>
<MenuItem onClick={() => menuActions.onClose()}> <MenuItem onClick={() => menuActions.onClose()}>
<Iconify icon="solar:printer-minimalistic-bold" /> <Iconify icon="solar:printer-minimalistic-bold" />
Print {t('Print')}
</MenuItem> </MenuItem>
<MenuItem onClick={() => menuActions.onClose()}> <MenuItem onClick={() => menuActions.onClose()}>
<Iconify icon="solar:import-bold" /> <Iconify icon="solar:import-bold" />
Import {t('Import')}
</MenuItem> </MenuItem>
<MenuItem onClick={() => menuActions.onClose()}> <MenuItem onClick={() => menuActions.onClose()}>
<Iconify icon="solar:export-bold" /> <Iconify icon="solar:export-bold" />
Export {t('Export')}
</MenuItem> </MenuItem>
</MenuList> </MenuList>
</CustomPopover> </CustomPopover>
@@ -93,7 +95,7 @@ export function OrderTableToolbar({ filters, onResetPage, dateError }: Props) {
}} }}
> >
<DatePicker <DatePicker
label="Start date" label={t('Start date')}
value={currentFilters.startDate} value={currentFilters.startDate}
onChange={handleFilterStartDate} onChange={handleFilterStartDate}
slotProps={{ textField: { fullWidth: true } }} slotProps={{ textField: { fullWidth: true } }}
@@ -101,7 +103,7 @@ export function OrderTableToolbar({ filters, onResetPage, dateError }: Props) {
/> />
<DatePicker <DatePicker
label="End date" label={t('End date')}
value={currentFilters.endDate} value={currentFilters.endDate}
onChange={handleFilterEndDate} onChange={handleFilterEndDate}
slotProps={{ slotProps={{
@@ -133,7 +135,7 @@ export function OrderTableToolbar({ filters, onResetPage, dateError }: Props) {
fullWidth fullWidth
value={currentFilters.name} value={currentFilters.name}
onChange={handleFilterName} onChange={handleFilterName}
placeholder="Search customer or order number..." placeholder={t('Search customer or order number...')}
slotProps={{ slotProps={{
input: { input: {
startAdornment: ( startAdornment: (

View File

@@ -1,3 +1,5 @@
// src/sections/order/view/order-list-view.tsx
import type { TableHeadCellProps } from 'src/components/table'; import type { TableHeadCellProps } from 'src/components/table';
import type { IOrderItem, IOrderTableFilters } from 'src/types/order'; import type { IOrderItem, IOrderTableFilters } from 'src/types/order';
@@ -43,30 +45,33 @@ import {
import { OrderTableRow } from '../order-table-row'; import { OrderTableRow } from '../order-table-row';
import { OrderTableToolbar } from '../order-table-toolbar'; import { OrderTableToolbar } from '../order-table-toolbar';
import { OrderTableFiltersResult } from '../order-table-filters-result'; import { OrderTableFiltersResult } from '../order-table-filters-result';
import { useTranslation } from 'react-i18next';
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
const STATUS_OPTIONS = [{ value: 'all', label: 'All' }, ...ORDER_STATUS_OPTIONS]; const STATUS_OPTIONS = [{ value: 'all', label: 'All' }, ...ORDER_STATUS_OPTIONS];
const TABLE_HEAD: TableHeadCellProps[] = [
{ id: 'orderNumber', label: 'Order', width: 88 },
{ id: 'name', label: 'Customer' },
{ id: 'createdAt', label: 'Date', width: 140 },
{ id: 'totalQuantity', label: 'Items', width: 120, align: 'center' },
{ id: 'totalAmount', label: 'Price', width: 140 },
{ id: 'status', label: 'Status', width: 110 },
{ id: '', width: 88 },
];
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
export function OrderListView() { export function OrderListView() {
const { t } = useTranslation();
const table = useTable({ defaultOrderBy: 'orderNumber' }); const table = useTable({ defaultOrderBy: 'orderNumber' });
const confirmDialog = useBoolean(); const confirmDialog = useBoolean();
const [tableData, setTableData] = useState<IOrderItem[]>(_orders); const [tableData, setTableData] = useState<IOrderItem[]>(_orders);
const TABLE_HEAD: TableHeadCellProps[] = [
{ id: 'orderNumber', label: t('Order'), width: 88 },
{ id: 'name', label: t('Customer') },
{ id: 'createdAt', label: t('Date'), width: 140 },
{ id: 'totalQuantity', label: t('Items'), width: 120, align: 'center' },
{ id: 'totalAmount', label: t('Price'), width: 140 },
{ id: 'status', label: t('Status'), width: 110 },
{ id: '', width: 88 },
];
const filters = useSetState<IOrderTableFilters>({ const filters = useSetState<IOrderTableFilters>({
name: '', name: '',
status: 'all', status: 'all',
@@ -143,7 +148,7 @@ export function OrderListView() {
confirmDialog.onFalse(); confirmDialog.onFalse();
}} }}
> >
Delete {t('Delete')}
</Button> </Button>
} }
/> />
@@ -155,9 +160,9 @@ export function OrderListView() {
<CustomBreadcrumbs <CustomBreadcrumbs
heading="List" heading="List"
links={[ links={[
{ name: 'Dashboard', href: paths.dashboard.root }, { name: t('Dashboard'), href: paths.dashboard.root },
{ name: 'Order', href: paths.dashboard.order.root }, { name: t('Order'), href: paths.dashboard.order.root },
{ name: 'List' }, { name: t('List') },
]} ]}
sx={{ mb: { xs: 3, md: 5 } }} sx={{ mb: { xs: 3, md: 5 } }}
/> />
@@ -178,7 +183,7 @@ export function OrderListView() {
key={tab.value} key={tab.value}
iconPosition="end" iconPosition="end"
value={tab.value} value={tab.value}
label={tab.label} label={t(tab.label)}
icon={ icon={
<Label <Label
variant={ variant={
@@ -228,7 +233,7 @@ export function OrderListView() {
) )
} }
action={ action={
<Tooltip title="Delete"> <Tooltip title={t('Delete')}>
<IconButton color="primary" onClick={confirmDialog.onTrue}> <IconButton color="primary" onClick={confirmDialog.onTrue}>
<Iconify icon="solar:trash-bin-trash-bold" /> <Iconify icon="solar:trash-bin-trash-bold" />
</IconButton> </IconButton>

View File

@@ -206,7 +206,6 @@ export function ProductNewEditForm({ currentProduct }: Props) {
if (currentProduct) { if (currentProduct) {
// perform save // perform save
await saveProduct(currentProduct.id, values); await saveProduct(currentProduct.id, values);
} else { } else {
// perform create // perform create
@@ -215,7 +214,8 @@ export function ProductNewEditForm({ currentProduct }: Props) {
toast.success(currentProduct ? 'Update success!' : 'Create success!'); toast.success(currentProduct ? 'Update success!' : 'Create success!');
// router.push(paths.dashboard.product.root); router.push(paths.dashboard.product.root);
// console.info('DATA', updatedData); // console.info('DATA', updatedData);
} catch (error) { } catch (error) {
console.error(error); console.error(error);

View File

@@ -1,3 +1,4 @@
// src/sections/product/product-table-row.tsx
import type { GridCellParams } from '@mui/x-data-grid'; import type { GridCellParams } from '@mui/x-data-grid';
import Box from '@mui/material/Box'; import Box from '@mui/material/Box';
@@ -43,7 +44,7 @@ export function RenderCellCreatedAt({ params }: ParamsProps) {
} }
export function RenderCellStock({ params }: ParamsProps) { export function RenderCellStock({ params }: ParamsProps) {
return <>helloworld</> return <>helloworld</>;
return ( return (
<Box sx={{ width: 1, typography: 'caption', color: 'text.secondary' }}> <Box sx={{ width: 1, typography: 'caption', color: 'text.secondary' }}>

View File

@@ -86,7 +86,7 @@ export function ProductDetailsView({ product, error, loading }: Props) {
<DashboardContent sx={{ pt: 5 }}> <DashboardContent sx={{ pt: 5 }}>
<EmptyContent <EmptyContent
filled filled
title="Product not found!" title={t('Product not found!')}
action={ action={
<Button <Button
component={RouterLink} component={RouterLink}
@@ -94,7 +94,7 @@ export function ProductDetailsView({ product, error, loading }: Props) {
startIcon={<Iconify width={16} icon="eva:arrow-ios-back-fill" />} startIcon={<Iconify width={16} icon="eva:arrow-ios-back-fill" />}
sx={{ mt: 3 }} sx={{ mt: 3 }}
> >
Back to list {t('Back to list')}
</Button> </Button>
} }
sx={{ py: 10, height: 'auto', flexGrow: 'unset' }} sx={{ py: 10, height: 'auto', flexGrow: 'unset' }}

View File

@@ -81,6 +81,11 @@ export function ProductListView() {
{ value: 'out of stock', label: t('Out of stock') }, { value: 'out of stock', label: t('Out of stock') },
]; ];
const PUBLISH_OPTIONS = [
{ value: 'published', label: t('Published') },
{ value: 'draft', label: t('Draft') },
];
useEffect(() => { useEffect(() => {
if (products.length) { if (products.length) {
setTableData(products); setTableData(products);
@@ -94,11 +99,6 @@ export function ProductListView() {
filters: currentFilters, filters: currentFilters,
}); });
const PUBLISH_OPTIONS = [
{ value: 'published', label: t('Published') },
{ value: 'draft', label: t('Draft') },
];
const handleDeleteSingleRow = useCallback(async () => { const handleDeleteSingleRow = useCallback(async () => {
// const deleteRow = tableData.filter((row) => row.id !== id); // const deleteRow = tableData.filter((row) => row.id !== id);
@@ -245,7 +245,7 @@ export function ProductListView() {
confirmDeleteMultiItemsDialog.onFalse(); confirmDeleteMultiItemsDialog.onFalse();
}} }}
> >
Delete {t('Delete')}
</Button> </Button>
} }
/> />
@@ -269,7 +269,7 @@ export function ProductListView() {
confirmDeleteSingleItemDialog.onFalse(); confirmDeleteSingleItemDialog.onFalse();
}} }}
> >
Delete {t('Delete')}
</Button> </Button>
} }
/> />
@@ -279,7 +279,7 @@ export function ProductListView() {
<> <>
<DashboardContent sx={{ flexGrow: 1, display: 'flex', flexDirection: 'column' }}> <DashboardContent sx={{ flexGrow: 1, display: 'flex', flexDirection: 'column' }}>
<CustomBreadcrumbs <CustomBreadcrumbs
heading="List" heading={t('Product List')}
links={[ links={[
{ name: t('Dashboard'), href: paths.dashboard.root }, { name: t('Dashboard'), href: paths.dashboard.root },
{ name: t('Product'), href: paths.dashboard.product.root }, { name: t('Product'), href: paths.dashboard.product.root },

View File

@@ -27,6 +27,7 @@ import { ProductDetailsReview } from '../product-details-review';
import { ProductDetailsSummary } from '../product-details-summary'; import { ProductDetailsSummary } from '../product-details-summary';
import { ProductDetailsCarousel } from '../product-details-carousel'; import { ProductDetailsCarousel } from '../product-details-carousel';
import { ProductDetailsDescription } from '../product-details-description'; import { ProductDetailsDescription } from '../product-details-description';
import { useTranslation } from 'react-i18next';
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@@ -57,6 +58,7 @@ type Props = {
}; };
export function ProductShopDetailsView({ product, error, loading }: Props) { export function ProductShopDetailsView({ product, error, loading }: Props) {
const { t } = useTranslation();
const { state: checkoutState, onAddToCart } = useCheckoutContext(); const { state: checkoutState, onAddToCart } = useCheckoutContext();
const containerStyles: SxProps<Theme> = { const containerStyles: SxProps<Theme> = {
@@ -79,7 +81,7 @@ export function ProductShopDetailsView({ product, error, loading }: Props) {
<Container sx={containerStyles}> <Container sx={containerStyles}>
<EmptyContent <EmptyContent
filled filled
title="Product not found!" title={t('Product not found!')}
action={ action={
<Button <Button
component={RouterLink} component={RouterLink}

View File

@@ -21,6 +21,7 @@ import { _socials } from 'src/_mock';
import { Iconify } from 'src/components/iconify'; import { Iconify } from 'src/components/iconify';
import { ProfilePostItem } from './profile-post-item'; import { ProfilePostItem } from './profile-post-item';
import { useTranslation } from 'react-i18next';
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@@ -31,6 +32,7 @@ type Props = {
export function ProfileHome({ info, posts }: Props) { export function ProfileHome({ info, posts }: Props) {
const fileRef = useRef<HTMLInputElement>(null); const fileRef = useRef<HTMLInputElement>(null);
const { t } = useTranslation();
const handleAttach = () => { const handleAttach = () => {
if (fileRef.current) { if (fileRef.current) {
@@ -40,21 +42,18 @@ export function ProfileHome({ info, posts }: Props) {
const renderFollows = () => ( const renderFollows = () => (
<Card sx={{ py: 3, textAlign: 'center', typography: 'h4' }}> <Card sx={{ py: 3, textAlign: 'center', typography: 'h4' }}>
<Stack <Stack divider={<Divider orientation="vertical" flexItem sx={{ borderStyle: 'dashed' }} />} sx={{ flexDirection: 'row' }}>
divider={<Divider orientation="vertical" flexItem sx={{ borderStyle: 'dashed' }} />}
sx={{ flexDirection: 'row' }}
>
<Stack sx={{ width: 1 }}> <Stack sx={{ width: 1 }}>
{fNumber(info.totalFollowers)} {fNumber(info.totalFollowers)}
<Box component="span" sx={{ color: 'text.secondary', typography: 'body2' }}> <Box component="span" sx={{ color: 'text.secondary', typography: 'body2' }}>
Follower {t('Follower')}
</Box> </Box>
</Stack> </Stack>
<Stack sx={{ width: 1 }}> <Stack sx={{ width: 1 }}>
{fNumber(info.totalFollowing)} {fNumber(info.totalFollowing)}
<Box component="span" sx={{ color: 'text.secondary', typography: 'body2' }}> <Box component="span" sx={{ color: 'text.secondary', typography: 'body2' }}>
Following {t('Following')}
</Box> </Box>
</Stack> </Stack>
</Stack> </Stack>
@@ -63,7 +62,7 @@ export function ProfileHome({ info, posts }: Props) {
const renderAbout = () => ( const renderAbout = () => (
<Card> <Card>
<CardHeader title="About" /> <CardHeader title={t('About')} />
<Box <Box
sx={{ sx={{
@@ -143,16 +142,16 @@ export function ProfileHome({ info, posts }: Props) {
> >
<Fab size="small" color="inherit" variant="softExtended" onClick={handleAttach}> <Fab size="small" color="inherit" variant="softExtended" onClick={handleAttach}>
<Iconify icon="solar:gallery-wide-bold" width={24} sx={{ color: 'success.main' }} /> <Iconify icon="solar:gallery-wide-bold" width={24} sx={{ color: 'success.main' }} />
Image/Video {t('Image/Video')}
</Fab> </Fab>
<Fab size="small" color="inherit" variant="softExtended"> <Fab size="small" color="inherit" variant="softExtended">
<Iconify icon="solar:videocamera-record-bold" width={24} sx={{ color: 'error.main' }} /> <Iconify icon="solar:videocamera-record-bold" width={24} sx={{ color: 'error.main' }} />
Streaming {t('Streaming')}
</Fab> </Fab>
</Box> </Box>
<Button variant="contained">Post</Button> <Button variant="contained">{t('Post')}</Button>
</Box> </Box>
<input ref={fileRef} type="file" style={{ display: 'none' }} /> <input ref={fileRef} type="file" style={{ display: 'none' }} />
@@ -161,7 +160,7 @@ export function ProfileHome({ info, posts }: Props) {
const renderSocials = () => ( const renderSocials = () => (
<Card> <Card>
<CardHeader title="Social" /> <CardHeader title={t('Social')} />
<Box sx={{ p: 3, gap: 2, display: 'flex', flexDirection: 'column', typography: 'body2' }}> <Box sx={{ p: 3, gap: 2, display: 'flex', flexDirection: 'column', typography: 'body2' }}>
{_socials.map((social) => ( {_socials.map((social) => (

View File

@@ -7,15 +7,18 @@ import Grid from '@mui/material/Grid';
import Stack from '@mui/material/Stack'; import Stack from '@mui/material/Stack';
import Switch from '@mui/material/Switch'; import Switch from '@mui/material/Switch';
import Typography from '@mui/material/Typography'; import Typography from '@mui/material/Typography';
import { useState } from 'react';
import { Controller, useForm } from 'react-hook-form'; import { Controller, useForm } from 'react-hook-form';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { isValidPhoneNumber } from 'react-phone-number-input/input'; import { isValidPhoneNumber } from 'react-phone-number-input/input';
import { createUser, deleteUser, saveUser } from 'src/actions/user';
import { Field, Form, schemaHelper } from 'src/components/hook-form'; import { Field, Form, schemaHelper } from 'src/components/hook-form';
import { Label } from 'src/components/label'; import { Label } from 'src/components/label';
import { toast } from 'src/components/snackbar'; import { toast } from 'src/components/snackbar';
import { useRouter } from 'src/routes/hooks'; import { useRouter } from 'src/routes/hooks';
import { paths } from 'src/routes/paths'; import { paths } from 'src/routes/paths';
import type { IUserItem } from 'src/types/user'; import type { IUserItem } from 'src/types/user';
import { fileToBase64 } from 'src/utils/file-to-base64';
import { fData } from 'src/utils/format-number'; import { fData } from 'src/utils/format-number';
import { z as zod } from 'zod'; import { z as zod } from 'zod';
@@ -24,26 +27,27 @@ import { z as zod } from 'zod';
export type NewUserSchemaType = zod.infer<typeof NewUserSchema>; export type NewUserSchemaType = zod.infer<typeof NewUserSchema>;
export const NewUserSchema = zod.object({ export const NewUserSchema = zod.object({
avatarUrl: schemaHelper.file({ message: 'Avatar is required!' }),
name: zod.string().min(1, { message: 'Name is required!' }), name: zod.string().min(1, { message: 'Name is required!' }),
city: zod.string().min(1, { message: 'City is required!' }),
role: zod.string().min(1, { message: 'Role is required!' }),
email: zod email: zod
.string() .string()
.min(1, { message: 'Email is required!' }) .min(1, { message: 'Email is required!' })
.email({ message: 'Email must be a valid email address!' }), .email({ message: 'Email must be a valid email address!' }),
phoneNumber: schemaHelper.phoneNumber({ isValid: isValidPhoneNumber }), state: zod.string().min(1, { message: 'State is required!' }),
status: zod.string(),
address: zod.string().min(1, { message: 'Address is required!' }),
country: schemaHelper.nullableInput(zod.string().min(1, { message: 'Country is required!' }), { country: schemaHelper.nullableInput(zod.string().min(1, { message: 'Country is required!' }), {
// message for null value // message for null value
message: 'Country is required!', message: 'Country is required!',
}), }),
address: zod.string().min(1, { message: 'Address is required!' }),
company: zod.string().min(1, { message: 'Company is required!' }),
state: zod.string().min(1, { message: 'State is required!' }),
city: zod.string().min(1, { message: 'City is required!' }),
role: zod.string().min(1, { message: 'Role is required!' }),
zipCode: zod.string().min(1, { message: 'Zip code is required!' }), zipCode: zod.string().min(1, { message: 'Zip code is required!' }),
// Not required company: zod.string().min(1, { message: 'Company is required!' }),
status: zod.string(), avatarUrl: schemaHelper.file({ message: 'Avatar is required!' }),
phoneNumber: schemaHelper.phoneNumber({ isValid: isValidPhoneNumber }),
isVerified: zod.boolean(), isVerified: zod.boolean(),
username: zod.string(),
password: zod.string(),
}); });
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@@ -61,16 +65,19 @@ export function UserNewEditForm({ currentUser }: Props) {
status: '', status: '',
avatarUrl: null, avatarUrl: null,
isVerified: true, isVerified: true,
name: '', name: '新用戶名字',
email: '', email: 'user@123.com',
phoneNumber: '', phoneNumber: '+85291234567',
country: '', country: 'Hong Kong',
state: '', state: 'HK',
city: '', city: 'hong kong',
address: '', address: 'Kwun Tong, Sau Mau Ping',
zipCode: '', zipCode: '00000',
company: '', company: 'test company',
role: '', role: 'user',
//
username: '',
password: '',
}; };
const methods = useForm<NewUserSchemaType>({ const methods = useForm<NewUserSchemaType>({
@@ -85,18 +92,50 @@ export function UserNewEditForm({ currentUser }: Props) {
watch, watch,
control, control,
handleSubmit, handleSubmit,
formState: { isSubmitting }, formState: { errors, isSubmitting },
} = methods; } = methods;
const values = watch(); const values = watch();
const onSubmit = handleSubmit(async (data) => { const [disableDeleteUserButton, setDisableDeleteUserButton] = useState<boolean>(false);
const handleDeleteUserClick = async () => {
setDisableDeleteUserButton(true);
try {
if (currentUser) {
await deleteUser(currentUser.id);
toast.success(t('user deleted'));
router.push(paths.dashboard.user.list);
}
} catch (error) {
console.error(error);
}
setDisableDeleteUserButton(false);
};
const onSubmit = handleSubmit(async (data: any) => {
try { try {
await new Promise((resolve) => setTimeout(resolve, 500)); await new Promise((resolve) => setTimeout(resolve, 500));
reset(); reset();
toast.success(currentUser ? 'Update success!' : 'Create success!');
const temp: any = data.avatarUrl;
if (temp instanceof File) {
data.avatarUrl = await fileToBase64(temp);
}
if (currentUser) {
// perform save
await saveUser(currentUser.id, data);
} else {
// perform create
await createUser(data);
}
toast.success(currentUser ? t('Update success!') : t('Create success!'));
router.push(paths.dashboard.user.list); router.push(paths.dashboard.user.list);
console.info('DATA', data);
// console.info('DATA', data);
} catch (error) { } catch (error) {
console.error(error); console.error(error);
} }
@@ -135,8 +174,8 @@ export function UserNewEditForm({ currentUser }: Props) {
color: 'text.disabled', color: 'text.disabled',
}} }}
> >
Allowed *.jpeg, *.jpg, *.png, *.gif {t('Allowed')} *.jpeg, *.jpg, *.png, *.gif
<br /> max size of {fData(3145728)} <br /> {t('max size of')} {fData(3145728)}
</Typography> </Typography>
} }
/> />
@@ -163,10 +202,10 @@ export function UserNewEditForm({ currentUser }: Props) {
label={ label={
<> <>
<Typography variant="subtitle2" sx={{ mb: 0.5 }}> <Typography variant="subtitle2" sx={{ mb: 0.5 }}>
Banned {t('Banned')}
</Typography> </Typography>
<Typography variant="body2" sx={{ color: 'text.secondary' }}> <Typography variant="body2" sx={{ color: 'text.secondary' }}>
Apply disable account {t('Apply disable account')}
</Typography> </Typography>
</> </>
} }
@@ -185,10 +224,10 @@ export function UserNewEditForm({ currentUser }: Props) {
label={ label={
<> <>
<Typography variant="subtitle2" sx={{ mb: 0.5 }}> <Typography variant="subtitle2" sx={{ mb: 0.5 }}>
Email verified {t('Email verified')}
</Typography> </Typography>
<Typography variant="body2" sx={{ color: 'text.secondary' }}> <Typography variant="body2" sx={{ color: 'text.secondary' }}>
Disabling this will automatically send the user a verification email {t('Disabling this will automatically send the user a verification email')}
</Typography> </Typography>
</> </>
} }
@@ -197,8 +236,14 @@ export function UserNewEditForm({ currentUser }: Props) {
{currentUser && ( {currentUser && (
<Stack sx={{ mt: 3, alignItems: 'center', justifyContent: 'center' }}> <Stack sx={{ mt: 3, alignItems: 'center', justifyContent: 'center' }}>
<Button variant="soft" color="error"> <Button
Delete user disabled={disableDeleteUserButton}
loading={disableDeleteUserButton}
variant="soft"
color="error"
onClick={handleDeleteUserClick}
>
{t('Delete user')}
</Button> </Button>
</Stack> </Stack>
)} )}
@@ -215,32 +260,33 @@ export function UserNewEditForm({ currentUser }: Props) {
gridTemplateColumns: { xs: 'repeat(1, 1fr)', sm: 'repeat(2, 1fr)' }, gridTemplateColumns: { xs: 'repeat(1, 1fr)', sm: 'repeat(2, 1fr)' },
}} }}
> >
<Field.Text name="name" label="Full name" /> <Field.Text name="name" label={t('Full name')} />
<Field.Text name="email" label="Email address" /> <Field.Text name="email" label={t('Email address')} />
<Field.Phone <Field.Phone name="phoneNumber" label={t('Phone number')} country="HK" />
name="phoneNumber"
label="Phone number"
country={!currentUser ? 'DE' : undefined}
/>
<Field.CountrySelect <Field.CountrySelect
fullWidth fullWidth
name="country" name="country"
label="Country" label={t('Country')}
placeholder="Choose a country" placeholder={t('Choose a country')}
/> />
<Field.Text name="state" label="State/region" /> <Field.Text name="state" label={t('State/region')} />
<Field.Text name="city" label="City" /> <Field.Text name="city" label={t('City')} />
<Field.Text name="address" label={t('Address')} /> <Field.Text name="address" label={t('Address')} />
<Field.Text name="zipCode" label="Zip/code" /> <Field.Text name="zipCode" label={t('Zip/code')} />
<Field.Text name="company" label="Company" /> <Field.Text name="company" label={t('Company')} />
<Field.Text name="role" label="Role" /> <Field.Text name="role" label={t('Role')} />
</Box> </Box>
<Stack sx={{ mt: 3, alignItems: 'flex-end' }}> <Stack sx={{ mt: 3, alignItems: 'flex-end' }}>
<Button type="submit" variant="contained" loading={isSubmitting}> <Button
{!currentUser ? 'Create user' : 'Save changes'} disabled={isSubmitting}
loading={isSubmitting}
type="submit"
variant="contained"
>
{!currentUser ? t('Create user') : t('Save changes')}
</Button> </Button>
</Stack> </Stack>
</Card> </Card>

View File

@@ -19,6 +19,7 @@ import { Label } from 'src/components/label';
import { RouterLink } from 'src/routes/components'; import { RouterLink } from 'src/routes/components';
import type { IUserItem } from 'src/types/user'; import type { IUserItem } from 'src/types/user';
import { UserQuickEditForm } from './user-quick-edit-form'; import { UserQuickEditForm } from './user-quick-edit-form';
import { useState } from 'react';
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@@ -55,7 +56,7 @@ export function UserTableRow({ row, selected, editHref, onSelectRow, onDeleteRow
<li> <li>
<MenuItem component={RouterLink} href={editHref} onClick={() => menuActions.onClose()}> <MenuItem component={RouterLink} href={editHref} onClick={() => menuActions.onClose()}>
<Iconify icon="solar:pen-bold" /> <Iconify icon="solar:pen-bold" />
Edit {t('Edit')}
</MenuItem> </MenuItem>
</li> </li>
@@ -67,21 +68,31 @@ export function UserTableRow({ row, selected, editHref, onSelectRow, onDeleteRow
sx={{ color: 'error.main' }} sx={{ color: 'error.main' }}
> >
<Iconify icon="solar:trash-bin-trash-bold" /> <Iconify icon="solar:trash-bin-trash-bold" />
Delete {t('Delete')}
</MenuItem> </MenuItem>
</MenuList> </MenuList>
</CustomPopover> </CustomPopover>
); );
const [disableDeleteButton, setDisableDeleteButton] = useState<boolean>(false);
const renderConfirmDialog = () => ( const renderConfirmDialog = () => (
<ConfirmDialog <ConfirmDialog
open={confirmDialog.value} open={confirmDialog.value}
onClose={confirmDialog.onFalse} onClose={confirmDialog.onFalse}
title="Delete" title={t('Delete')}
content="Are you sure want to delete?" content={t('Are you sure want to delete user?')}
action={ action={
<Button variant="contained" color="error" onClick={onDeleteRow}> <Button
Delete disabled={disableDeleteButton}
loading={disableDeleteButton}
variant="contained"
color="error"
onClick={() => {
setDisableDeleteButton(true);
onDeleteRow();
}}
>
{t('Delete')}
</Button> </Button>
} }
/> />

View File

@@ -10,27 +10,25 @@ import { Iconify } from 'src/components/iconify';
import { CustomBreadcrumbs } from 'src/components/custom-breadcrumbs'; import { CustomBreadcrumbs } from 'src/components/custom-breadcrumbs';
import { UserCardList } from '../user-card-list'; import { UserCardList } from '../user-card-list';
import { useTranslation } from 'react-i18next';
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
export function UserCardsView() { export function UserCardsView() {
const { t } = useTranslation();
return ( return (
<DashboardContent> <DashboardContent>
<CustomBreadcrumbs <CustomBreadcrumbs
heading="User cards" heading="User cards"
links={[ links={[
{ name: 'Dashboard', href: paths.dashboard.root }, //
{ name: 'User', href: paths.dashboard.user.root }, { name: t('Dashboard'), href: paths.dashboard.root },
{ name: 'Cards' }, { name: t('User'), href: paths.dashboard.user.root },
{ name: t('Cards') },
]} ]}
action={ action={
<Button <Button component={RouterLink} href={paths.dashboard.user.new} variant="contained" startIcon={<Iconify icon="mingcute:add-line" />}>
component={RouterLink} {t('New user')}
href={paths.dashboard.user.new}
variant="contained"
startIcon={<Iconify icon="mingcute:add-line" />}
>
New user
</Button> </Button>
} }
sx={{ mb: { xs: 3, md: 5 } }} sx={{ mb: { xs: 3, md: 5 } }}

View File

@@ -5,18 +5,22 @@ import { DashboardContent } from 'src/layouts/dashboard';
import { CustomBreadcrumbs } from 'src/components/custom-breadcrumbs'; import { CustomBreadcrumbs } from 'src/components/custom-breadcrumbs';
import { UserNewEditForm } from '../user-new-edit-form'; import { UserNewEditForm } from '../user-new-edit-form';
import { useTranslation } from 'react-i18next';
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
export function UserCreateView() { export function UserCreateView() {
const { t } = useTranslation();
return ( return (
<DashboardContent> <DashboardContent>
<CustomBreadcrumbs <CustomBreadcrumbs
heading="Create a new user" heading={t('Create a new user')}
links={[ links={[
{ name: 'Dashboard', href: paths.dashboard.root }, //
{ name: 'User', href: paths.dashboard.user.root }, { name: t('Dashboard'), href: paths.dashboard.root },
{ name: 'New user' }, { name: t('User'), href: paths.dashboard.user.root },
{ name: t('New user') },
]} ]}
sx={{ mb: { xs: 3, md: 5 } }} sx={{ mb: { xs: 3, md: 5 } }}
/> />

View File

@@ -3,6 +3,7 @@ import { DashboardContent } from 'src/layouts/dashboard';
import { paths } from 'src/routes/paths'; import { paths } from 'src/routes/paths';
import type { IUserItem } from 'src/types/user'; import type { IUserItem } from 'src/types/user';
import { UserNewEditForm } from '../user-new-edit-form'; import { UserNewEditForm } from '../user-new-edit-form';
import { useTranslation } from 'react-i18next';
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@@ -11,14 +12,16 @@ type Props = {
}; };
export function UserEditView({ user: currentUser }: Props) { export function UserEditView({ user: currentUser }: Props) {
const { t } = useTranslation();
return ( return (
<DashboardContent> <DashboardContent>
<CustomBreadcrumbs <CustomBreadcrumbs
heading="Edit" heading="Edit"
backHref={paths.dashboard.user.list} backHref={paths.dashboard.user.list}
links={[ links={[
{ name: 'Dashboard', href: paths.dashboard.root }, { name: t('Dashboard'), href: paths.dashboard.root },
{ name: 'User', href: paths.dashboard.user.root }, { name: t('User'), href: paths.dashboard.user.root },
{ name: currentUser?.name }, { name: currentUser?.name },
]} ]}
sx={{ mb: { xs: 3, md: 5 } }} sx={{ mb: { xs: 3, md: 5 } }}

View File

@@ -13,7 +13,7 @@ import { varAlpha } from 'minimal-shared/utils';
import { useCallback, useEffect, useState } from 'react'; import { useCallback, useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { _roles, _userList, USER_STATUS_OPTIONS } from 'src/_mock'; import { _roles, _userList, USER_STATUS_OPTIONS } from 'src/_mock';
import { useGetUsers } from 'src/actions/user'; import { deleteUser, useGetUsers } from 'src/actions/user';
import { CustomBreadcrumbs } from 'src/components/custom-breadcrumbs'; import { CustomBreadcrumbs } from 'src/components/custom-breadcrumbs';
import { ConfirmDialog } from 'src/components/custom-dialog'; import { ConfirmDialog } from 'src/components/custom-dialog';
import { Iconify } from 'src/components/iconify'; import { Iconify } from 'src/components/iconify';
@@ -39,6 +39,8 @@ import type { IUserItem, IUserTableFilters } from 'src/types/user';
import { UserTableFiltersResult } from '../user-table-filters-result'; import { UserTableFiltersResult } from '../user-table-filters-result';
import { UserTableRow } from '../user-table-row'; import { UserTableRow } from '../user-table-row';
import { UserTableToolbar } from '../user-table-toolbar'; import { UserTableToolbar } from '../user-table-toolbar';
import { Router } from 'react-router';
import { useRouter } from 'src/routes/hooks';
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@@ -48,6 +50,7 @@ const STATUS_OPTIONS = [{ value: 'all', label: 'All' }, ...USER_STATUS_OPTIONS];
export function UserListView() { export function UserListView() {
const { t } = useTranslation(); const { t } = useTranslation();
const router = useRouter();
const TABLE_HEAD: TableHeadCellProps[] = [ const TABLE_HEAD: TableHeadCellProps[] = [
{ id: 'name', label: t('Name') }, { id: 'name', label: t('Name') },
@@ -59,12 +62,13 @@ export function UserListView() {
]; ];
const { users, mutate } = useGetUsers(); const { users, mutate } = useGetUsers();
const [processNewUser, setProcessNewUser] = useState<boolean>(false);
const table = useTable(); const table = useTable();
const confirmDialog = useBoolean(); const confirmDialog = useBoolean();
const [tableData, setTableData] = useState<IUserItem[]>(_userList); const [tableData, setTableData] = useState<IUserItem[]>([]);
useEffect(() => { useEffect(() => {
setTableData(users); setTableData(users);
@@ -87,16 +91,22 @@ export function UserListView() {
const notFound = (!dataFiltered.length && canReset) || !dataFiltered.length; const notFound = (!dataFiltered.length && canReset) || !dataFiltered.length;
const handleDeleteRow = useCallback( const handleDeleteRow = useCallback(
(id: string) => { async (id: string) => {
const deleteRow = tableData.filter((row) => row.id !== id); // const deleteRow = tableData.filter((row) => row.id !== id);
// toast.success('Delete success!');
// setTableData(deleteRow);
// table.onUpdatePageDeleteRow(dataInPage.length);
toast.success('Delete success!'); try {
await deleteUser(id);
setTableData(deleteRow); toast.success('Delete success!');
mutate();
table.onUpdatePageDeleteRow(dataInPage.length); } catch (error) {
console.error(error);
toast.error('Delete failed!');
}
}, },
[dataInPage.length, table, tableData] [table, tableData, mutate]
); );
const handleDeleteRows = useCallback(() => { const handleDeleteRows = useCallback(() => {
@@ -121,7 +131,7 @@ export function UserListView() {
<ConfirmDialog <ConfirmDialog
open={confirmDialog.value} open={confirmDialog.value}
onClose={confirmDialog.onFalse} onClose={confirmDialog.onFalse}
title="Delete" title={t('Delete')}
content={ content={
<> <>
Are you sure want to delete <strong> {table.selected.length} </strong> items? Are you sure want to delete <strong> {table.selected.length} </strong> items?
@@ -133,7 +143,7 @@ export function UserListView() {
color="error" color="error"
onClick={() => { onClick={() => {
handleDeleteRows(); handleDeleteRows();
confirmDialog.onFalse(); // confirmDialog.onFalse();
}} }}
> >
{t('Delete')} {t('Delete')}
@@ -142,22 +152,33 @@ export function UserListView() {
/> />
); );
useEffect(() => {
mutate();
}, []);
return ( return (
<> <>
<DashboardContent> <DashboardContent>
<CustomBreadcrumbs <CustomBreadcrumbs
heading="List" heading="List"
links={[ links={[
{ name: 'Dashboard', href: paths.dashboard.root }, //
{ name: 'User', href: paths.dashboard.user.root }, { name: t('Dashboard'), href: paths.dashboard.root },
{ name: 'List' }, { name: t('User'), href: paths.dashboard.user.root },
{ name: t('List') },
]} ]}
action={ action={
<Button <Button
component={RouterLink} disabled={processNewUser}
href={paths.dashboard.user.new} loading={processNewUser}
// component={RouterLink}
// href={paths.dashboard.user.new}
variant="contained" variant="contained"
startIcon={<Iconify icon="mingcute:add-line" />} startIcon={<Iconify icon="mingcute:add-line" />}
onClick={() => {
setProcessNewUser(true);
router.push(paths.dashboard.user.new);
}}
> >
{t('New user')} {t('New user')}
</Button> </Button>

View File

@@ -22,6 +22,7 @@ import { ProfileCover } from '../profile-cover';
import { ProfileFriends } from '../profile-friends'; import { ProfileFriends } from '../profile-friends';
import { ProfileGallery } from '../profile-gallery'; import { ProfileGallery } from '../profile-gallery';
import { ProfileFollowers } from '../profile-followers'; import { ProfileFollowers } from '../profile-followers';
import { useTranslation } from 'react-i18next';
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@@ -53,6 +54,8 @@ const NAV_ITEMS = [
const TAB_PARAM = 'tab'; const TAB_PARAM = 'tab';
export function UserProfileView() { export function UserProfileView() {
const { t } = useTranslation();
const pathname = usePathname(); const pathname = usePathname();
const searchParams = useSearchParams(); const searchParams = useSearchParams();
const selectedTab = searchParams.get(TAB_PARAM) ?? ''; const selectedTab = searchParams.get(TAB_PARAM) ?? '';
@@ -74,21 +77,12 @@ export function UserProfileView() {
<DashboardContent> <DashboardContent>
<CustomBreadcrumbs <CustomBreadcrumbs
heading="Profile" heading="Profile"
links={[ links={[{ name: t('Dashboard'), href: paths.dashboard.root }, { name: t('User'), href: paths.dashboard.user.root }, { name: user?.displayName }]}
{ name: 'Dashboard', href: paths.dashboard.root },
{ name: 'User', href: paths.dashboard.user.root },
{ name: user?.displayName },
]}
sx={{ mb: { xs: 3, md: 5 } }} sx={{ mb: { xs: 3, md: 5 } }}
/> />
<Card sx={{ mb: 3, height: 290 }}> <Card sx={{ mb: 3, height: 290 }}>
<ProfileCover <ProfileCover role={_userAbout.role} name={user?.displayName} avatarUrl={user?.photoURL} coverUrl={_userAbout.coverUrl} />
role={_userAbout.role}
name={user?.displayName}
avatarUrl={user?.photoURL}
coverUrl={_userAbout.coverUrl}
/>
<Box <Box
sx={{ sx={{
@@ -109,7 +103,7 @@ export function UserProfileView() {
key={tab.value} key={tab.value}
value={tab.value} value={tab.value}
icon={tab.icon} icon={tab.icon}
label={tab.label} label={t(tab.label)}
href={createRedirectPath(pathname, tab.value)} href={createRedirectPath(pathname, tab.value)}
/> />
))} ))}
@@ -121,13 +115,7 @@ export function UserProfileView() {
{selectedTab === 'followers' && <ProfileFollowers followers={_userFollowers} />} {selectedTab === 'followers' && <ProfileFollowers followers={_userFollowers} />}
{selectedTab === 'friends' && ( {selectedTab === 'friends' && <ProfileFriends friends={_userFriends} searchFriends={searchFriends} onSearchFriends={handleSearchFriends} />}
<ProfileFriends
friends={_userFriends}
searchFriends={searchFriends}
onSearchFriends={handleSearchFriends}
/>
)}
{selectedTab === 'gallery' && <ProfileGallery gallery={_userGallery} />} {selectedTab === 'gallery' && <ProfileGallery gallery={_userGallery} />}
</DashboardContent> </DashboardContent>

View File

@@ -34,6 +34,11 @@ if (navigator_language.startsWith('sc')) primaryFont = 'Noto Sans SC Variable';
// TODO: not tested, T.B.C. // TODO: not tested, T.B.C.
if (navigator_language.startsWith('jp')) primaryFont = 'Noto Sans JP Variable'; if (navigator_language.startsWith('jp')) primaryFont = 'Noto Sans JP Variable';
console.log({
navigator_language,
primaryFont,
});
export const themeConfig: ThemeConfig = { export const themeConfig: ThemeConfig = {
/** ************************************** /** **************************************
* Base * Base

View File

@@ -89,6 +89,9 @@ export type IUserItem = {
avatarUrl: string; avatarUrl: string;
phoneNumber: string; phoneNumber: string;
isVerified: boolean; isVerified: boolean;
//
username: string;
password: string;
}; };
export type IUserAccountBillingHistory = { export type IUserAccountBillingHistory = {

View File

@@ -33,4 +33,7 @@ export default defineConfig({
}, },
server: { port: PORT, host: true }, server: { port: PORT, host: true },
preview: { port: PORT, host: true }, preview: { port: PORT, host: true },
build: {
sourcemap: true,
},
}); });