-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(admin): ✨ category admin panel init
- Loading branch information
Showing
9 changed files
with
351 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = { | ||
reactStrictMode: true, | ||
} | ||
reactStrictMode: true, | ||
images: { | ||
domains: ["images.unsplash.com"], | ||
}, | ||
}; | ||
|
||
module.exports = nextConfig | ||
module.exports = nextConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
query Categories { | ||
categories { | ||
id | ||
name | ||
identifier | ||
desc | ||
imageURL | ||
tenantId | ||
created_at | ||
updated_at | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
/* eslint-disable no-nested-ternary */ | ||
import { | ||
Flex, | ||
FormControl, | ||
FormLabel, | ||
HStack, | ||
Input, | ||
InputGroup, | ||
InputLeftElement, | ||
Select, | ||
Spinner, | ||
Stack, | ||
Text, | ||
VStack, | ||
} from "@chakra-ui/react"; | ||
import { BsSearch } from "react-icons/bs"; | ||
import { CellContext, createColumnHelper } from "@tanstack/react-table"; | ||
import Image from "next/image"; | ||
import Result from "@/components/shared/Result"; | ||
import HeadingGroup from "@/components/ui/HeadingGroup"; | ||
import { DataTable } from "@/components/ui/table"; | ||
import { type ProductCategory, useCategoriesQuery } from "@/generated/graphql"; | ||
import ConfirmationModal from "@/components/helpers/ConfirmationModal"; | ||
import ModalButton from "@/components/ui/ModalButton"; | ||
|
||
export const TableActions = () => ( | ||
<Stack | ||
w="full" | ||
spacing="4" | ||
direction={{ base: "column", md: "row" }} | ||
justify="space-between" | ||
position="sticky" | ||
top="0" | ||
> | ||
<HStack> | ||
<FormControl minW={{ md: "320px" }} id="search"> | ||
<InputGroup size="sm"> | ||
<FormLabel srOnly>Filter by name or email</FormLabel> | ||
<InputLeftElement pointerEvents="none" color="gray.400"> | ||
<BsSearch /> | ||
</InputLeftElement> | ||
<Input | ||
// value={searchText} | ||
// onChange={(e) => setSearchText(e.target.value)} | ||
rounded="base" | ||
type="search" | ||
placeholder="Filter by name or email..." | ||
/> | ||
</InputGroup> | ||
</FormControl> | ||
<Select | ||
w={{ base: "300px", md: "full" }} | ||
rounded="base" | ||
size="sm" | ||
// value={selectedRole} | ||
// onChange={(e) => setSelectedRole(Number(e.target.value))} | ||
> | ||
<option value={0}>All categories</option> | ||
{/* {categoriesData?.categories | ||
.filter((r) => r.id !== 1) | ||
.map((role) => ( | ||
<option key={`role-${role.id}`} value={role.id}> | ||
{role.name} | ||
</option> | ||
))} */} | ||
</Select> | ||
</HStack> | ||
</Stack> | ||
); | ||
|
||
const columnHelper = createColumnHelper<ProductCategory>(); | ||
|
||
const columns = [ | ||
// columnHelper.accessor("name", { | ||
// cell: (info) => <Checkbox size="lg" />, | ||
// header: "", | ||
// }), | ||
columnHelper.accessor("name", { | ||
cell: (info) => ( | ||
<HStack spacing="4" px="2" w="full"> | ||
<Image | ||
alt={info.getValue()} | ||
height={48} | ||
width={48} | ||
src={info.row.original.imageURL} | ||
style={{ | ||
borderRadius: "4px", | ||
}} | ||
/> | ||
<Flex direction="column"> | ||
<Text fontWeight="medium">{info.getValue()} </Text> | ||
</Flex> | ||
</HStack> | ||
), | ||
header: "Name", | ||
}), | ||
columnHelper.accessor("desc", { | ||
cell: (info) => info.getValue(), | ||
header: "Desc", | ||
}), | ||
// columnHelper.accessor("user", { | ||
// cell: (info) => ( | ||
// <UserProfile | ||
// email={info.getValue()?.email ?? ""} | ||
// imageUrl={info.getValue()?.imageUrl ?? ""} | ||
// name={`${info.getValue()?.first_name} ${info.getValue()?.last_name}`} | ||
// /> | ||
// ), | ||
// header: "User", | ||
// }), | ||
// columnHelper.accessor("user.role", { | ||
// cell: (info) => <RoleSelector info={info} />, | ||
// header: "Role", | ||
// }), | ||
// columnHelper.accessor("status", { | ||
// cell: (info) => ( | ||
// <Badge fontSize="xs" colorScheme={colorFromStatus(info.getValue())}> | ||
// {info.getValue()} | ||
// </Badge> | ||
// ), | ||
// header: "Status", | ||
// }), | ||
columnHelper.accessor("id", { | ||
cell: (info) => <CategoryActions info={info} />, | ||
header: "Actions", | ||
}), | ||
]; | ||
|
||
const CategoryActions = ({ | ||
info, | ||
}: { | ||
info: CellContext<ProductCategory, number>; | ||
}) => ( | ||
<HStack gap={2}> | ||
<ModalButton | ||
modalHeader={`Edit ${info.row.original.name}`} | ||
size="sm" | ||
colorScheme="primary" | ||
buttonText="Edit" | ||
> | ||
Editing | ||
</ModalButton> | ||
<ConfirmationModal | ||
bodyText={`Are you sure you want to delete category ${info.row.original.name}?`} | ||
confirmButtonProps={{ colorScheme: "red" }} | ||
headerText={`Delete Category ${info.row.original.name}?`} | ||
onSuccess={() => { | ||
console.log("Deleted"); | ||
}} | ||
size="sm" | ||
confirmText="delete" | ||
colorScheme="red" | ||
> | ||
Delete | ||
</ConfirmationModal> | ||
</HStack> | ||
); | ||
|
||
const SettingsPage = () => { | ||
const { data, loading, error } = useCategoriesQuery(); | ||
|
||
if (error) { | ||
return ( | ||
<Result | ||
heading={error.name} | ||
text={error.message} | ||
type="error" | ||
dump={error.stack} | ||
/> | ||
); | ||
} | ||
|
||
return ( | ||
<VStack gap={4} w="full"> | ||
<HeadingGroup | ||
title="Manage Staffs" | ||
description="Manage your staffs here." | ||
/> | ||
<TableActions /> | ||
{loading ? ( | ||
<Spinner /> | ||
) : ( | ||
<DataTable | ||
columns={columns} | ||
data={data?.categories as ProductCategory[]} | ||
/> | ||
)} | ||
</VStack> | ||
); | ||
}; | ||
|
||
export default SettingsPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const CategoryPage = () => <div>CategoryPage</div>; | ||
|
||
export default CategoryPage; |
Oops, something went wrong.
128242b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
ecommerce-admin-client – ./apps/admin
ecommerce-admin-client-git-main-sahrohit.vercel.app
adminpasal.vercel.app
ecommerce-admin-client-sahrohit.vercel.app
128242b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
ecommerce-storefront-client – ./apps/storefront
ecommerce-storefront-client-sahrohit.vercel.app
ecommerce-storefront-client-git-main-sahrohit.vercel.app
www.rudejellyfish.live
hamropasal.vercel.app
rudejellyfish.live