Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Commit

Permalink
refactor: clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
foxminchan committed Jun 3, 2024
1 parent f36d71f commit 6e92cb0
Show file tree
Hide file tree
Showing 22 changed files with 121 additions and 145 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public static ProductVm ToProductVm(this ProductDto product) =>
product.AverageRating,
product.TotalReviews,
product.Status,
product.CreatedDate,
product.UpdatedDate,
product.Category);

public static List<ProductVm> ToProductVm(this IEnumerable<ProductDto> products) =>
Expand Down
2 changes: 2 additions & 0 deletions src/RookieShop.ApiService/ViewModels/Products/ProductVm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ public sealed record ProductVm(
double AverageRating,
int TotalReviews,
ProductStatus Status,
DateTime CreatedDate,
DateTime? UpdatedDate,
CategoryDto? Category);
2 changes: 2 additions & 0 deletions src/RookieShop.Application/Products/DTOs/DomainToDtoMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public static ProductDto ToProductDto(this Product product)
product.AverageRating,
product.TotalReviews,
product.Status,
product.CreatedDate,
product.UpdateDate,
category);
}

Expand Down
2 changes: 2 additions & 0 deletions src/RookieShop.Application/Products/DTOs/ProductDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ public sealed record ProductDto(
double AverageRating,
int TotalReviews,
ProductStatus Status,
DateTime CreatedDate,
DateTime? UpdatedDate,
CategoryDto? Category);
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public static ISpecificationBuilder<Product> ApplyOrdering(this ISpecificationBu
nameof(Product.Price) => isDescending
? builder.OrderByDescending(product => product.Price.Price)
: builder.OrderBy(product => product.Price.Price),
nameof(Product.Price.PriceSale) => isDescending
? builder.OrderByDescending(product => product.Price.PriceSale)
: builder.OrderBy(product => product.Price.PriceSale),
nameof(Product.Status) => isDescending
? builder.OrderByDescending(product => product.Status)
: builder.OrderBy(product => product.Status),
Expand Down
4 changes: 2 additions & 2 deletions ui/backoffice/app/(dashboard)/dashboard/category/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

import Link from "next/link"
import useListCategories from "@/features/category/useListCategories"
import { Plus } from "lucide-react"

import { DEFAULT_PAGE_INDEX, DEFAULT_PAGE_SIZE } from "@/lib/constants/default"
import { cn } from "@/lib/utils"
import Breadcrumb from "@/components/ui/breadcrumb"
import { buttonVariants } from "@/components/ui/button"
import { Heading } from "@/components/ui/heading"
import { Separator } from "@/components/ui/separator"
import { Icons } from "@/components/custom/icons"
import CategoryTable from "@/components/tables/category/table"

const breadcrumbItems = [{ title: "Category", link: "/dashboard/category" }]
Expand Down Expand Up @@ -46,7 +46,7 @@ export default function CatgoryPage({ searchParams }: Readonly<paramsProps>) {
href={"/dashboard/category/new"}
className={cn(buttonVariants({ variant: "default" }))}
>
<Plus className="mr-2 h-4 w-4" /> Add New
<Icons.add className="mr-2 h-4 w-4" /> Add New
</Link>
</div>
<Separator />
Expand Down
4 changes: 2 additions & 2 deletions ui/backoffice/app/(dashboard)/dashboard/product/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import Link from "next/link"
import useListProducts from "@/features/product/useListProducts"
import { Plus } from "lucide-react"

import {
DEFAULT_ORDER_BY,
Expand All @@ -14,6 +13,7 @@ import Breadcrumb from "@/components/ui/breadcrumb"
import { buttonVariants } from "@/components/ui/button"
import { Heading } from "@/components/ui/heading"
import { Separator } from "@/components/ui/separator"
import { Icons } from "@/components/custom/icons"
import ProductTable from "@/components/tables/product/table"

const breadcrumbItems = [{ title: "Product", link: "/dashboard/product" }]
Expand Down Expand Up @@ -54,7 +54,7 @@ export default function ProductPage({ searchParams }: Readonly<paramsProps>) {
href={"/dashboard/product/new"}
className={cn(buttonVariants({ variant: "default" }))}
>
<Plus className="mr-2 h-4 w-4" /> Add New
<Icons.add className="mr-2 h-4 w-4" /> Add New
</Link>
</div>
<Separator />
Expand Down
9 changes: 6 additions & 3 deletions ui/backoffice/components/custom/file-upload.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
"use client"

import Image from "next/image"
import { Trash } from "lucide-react"

import { IMG_MAX_SIZE } from "@/lib/constants/default"

import { Button } from "../ui/button"
import { Input } from "../ui/input"
import { Label } from "../ui/label"
import { useToast } from "../ui/use-toast"
import { Icons } from "./icons"

type ImageUploadProps = {
onChange?: any
value?: File | null
}

export default function FileUpload({ onChange, value }: ImageUploadProps) {
export default function FileUpload({
onChange,
value,
}: Readonly<ImageUploadProps>) {
const { toast } = useToast()

const onDeleteFile = () => {
Expand All @@ -34,7 +37,7 @@ export default function FileUpload({ onChange, value }: ImageUploadProps) {
variant="destructive"
size="sm"
>
<Trash className="h-4 w-4" />
<Icons.trash className="h-4 w-4" />
</Button>
</div>
<div>
Expand Down
7 changes: 4 additions & 3 deletions ui/backoffice/components/custom/filter-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
PaginationState,
useReactTable,
} from "@tanstack/react-table"
import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react"

import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
Expand All @@ -36,6 +35,8 @@ import {
TableRow,
} from "@/components/ui/table"

import { Icons } from "./icons"

export default function FilterTable<TData, TValue>({
columns,
data,
Expand Down Expand Up @@ -249,7 +250,7 @@ export default function FilterTable<TData, TValue>({
onClick={() => table.previousPage()}
disabled={!table.getCanPreviousPage()}
>
<ChevronLeftIcon className="h-4 w-4" aria-hidden="true" />
<Icons.chevronLeft className="h-4 w-4" aria-hidden="true" />
</Button>
<Button
aria-label="Go to next page"
Expand All @@ -258,7 +259,7 @@ export default function FilterTable<TData, TValue>({
onClick={() => table.nextPage()}
disabled={!table.getCanNextPage()}
>
<ChevronRightIcon className="h-4 w-4" aria-hidden="true" />
<Icons.chevronRight className="h-4 w-4" aria-hidden="true" />
</Button>
<Button
aria-label="Go to last page"
Expand Down
8 changes: 8 additions & 0 deletions ui/backoffice/components/custom/icons.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import {
AlertTriangle,
ArrowRight,
ArrowUpDown,
Book,
Check,
ChevronLeft,
ChevronRight,
CreditCard,
Edit,
File,
FileText,
HelpCircle,
Expand All @@ -14,7 +16,9 @@ import {
Loader2,
LockKeyhole,
LucideIcon,
Minus,
Moon,
MoreHorizontal,
MoreVertical,
Package,
Pizza,
Expand Down Expand Up @@ -58,4 +62,8 @@ export const Icons = {
category: Book,
customer: User,
order: Receipt,
minus: Minus,
arrow: ArrowUpDown,
more: MoreHorizontal,
edit: Edit,
}
4 changes: 2 additions & 2 deletions ui/backoffice/components/custom/loading-button.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react"
import { Loader2 } from "lucide-react"

import { Button, ButtonProps } from "../ui/button"
import { Icons } from "./icons"

export interface LoadingButtonProps extends ButtonProps {
isLoading?: boolean
Expand All @@ -12,7 +12,7 @@ export default function LoadingButton({
isLoading = false,
loadingHolder = (
<>
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
<Icons.spinner className="mr-2 h-4 w-4 animate-spin" />
{"Please wait"}
</>
),
Expand Down
7 changes: 4 additions & 3 deletions ui/backoffice/components/custom/mode-toggle.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"use client"

import * as React from "react"
import { Moon, Sun } from "lucide-react"
import { useTheme } from "next-themes"

import { Button } from "@/components/ui/button"
Expand All @@ -12,15 +11,17 @@ import {
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"

import { Icons } from "./icons"

export default function ModeToggle() {
const { setTheme } = useTheme()

return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="outline" size="icon">
<Sun className="h-[1.2rem] w-[1.2rem] rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0" />
<Moon className="absolute h-[1.2rem] w-[1.2rem] rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100" />
<Icons.sun className="h-[1.2rem] w-[1.2rem] rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0" />
<Icons.moon className="absolute h-[1.2rem] w-[1.2rem] rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100" />
<span className="sr-only">Toggle theme</span>
</Button>
</DropdownMenuTrigger>
Expand Down
8 changes: 4 additions & 4 deletions ui/backoffice/components/tables/category/cell-action.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { usePathname, useRouter } from "next/navigation"
import { Category } from "@/features/category/category.type"
import useDeleteCategory from "@/features/category/useDeleteCategory"
import useListCategories from "@/features/category/useListCategories"
import { Edit, MoreHorizontal, Trash } from "lucide-react"

import { Button } from "@/components/ui/button"
import {
Expand All @@ -15,6 +14,7 @@ import {
DropdownMenuLabel,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"
import { Icons } from "@/components/custom/icons"
import { AlertModal } from "@/components/modals/alert-modal"

type CellActionProps = {
Expand Down Expand Up @@ -50,18 +50,18 @@ export const CellAction: FC<CellActionProps> = ({ data }) => {
<DropdownMenuTrigger asChild>
<Button variant="ghost" className="h-8 w-8 p-0">
<span className="sr-only">Open menu</span>
<MoreHorizontal className="h-4 w-4" />
<Icons.more className="h-4 w-4" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuLabel>Actions</DropdownMenuLabel>
<DropdownMenuItem
onClick={() => router.push(`${categoryPath}/${data.id}`)}
>
<Edit className="mr-2 h-4 w-4" /> Update
<Icons.edit className="mr-2 h-4 w-4" /> Update
</DropdownMenuItem>
<DropdownMenuItem onClick={() => setOpen(true)}>
<Trash className="mr-2 h-4 w-4" /> Delete
<Icons.trash className="mr-2 h-4 w-4" /> Delete
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
Expand Down
21 changes: 0 additions & 21 deletions ui/backoffice/components/tables/category/columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,9 @@
import { Category } from "@/features/category/category.type"
import { ColumnDef } from "@tanstack/react-table"

import { Checkbox } from "@/components/ui/checkbox"

import { CellAction } from "./cell-action"

export const columns: ColumnDef<Category>[] = [
{
id: "select",
header: ({ table }) => (
<Checkbox
checked={table.getIsAllPageRowsSelected()}
onCheckedChange={(value) => table.toggleAllPageRowsSelected(!!value)}
aria-label="Select all"
/>
),
cell: ({ row }) => (
<Checkbox
checked={row.getIsSelected()}
onCheckedChange={(value) => row.toggleSelected(!!value)}
aria-label="Select row"
/>
),
enableSorting: false,
enableHiding: false,
},
{
accessorKey: "name",
header: "NAME",
Expand Down
20 changes: 0 additions & 20 deletions ui/backoffice/components/tables/customer/columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,8 @@ import { ColumnDef } from "@tanstack/react-table"

import { cn } from "@/lib/utils"
import { Badge } from "@/components/ui/badge"
import { Checkbox } from "@/components/ui/checkbox"

export const columns: ColumnDef<Customer>[] = [
{
id: "select",
header: ({ table }) => (
<Checkbox
checked={table.getIsAllPageRowsSelected()}
onCheckedChange={(value) => table.toggleAllPageRowsSelected(!!value)}
aria-label="Select all"
/>
),
cell: ({ row }) => (
<Checkbox
checked={row.getIsSelected()}
onCheckedChange={(value) => row.toggleSelected(!!value)}
aria-label="Select row"
/>
),
enableSorting: false,
enableHiding: false,
},
{
accessorKey: "name",
header: "NAME",
Expand Down
6 changes: 3 additions & 3 deletions ui/backoffice/components/tables/feedback/cell-action.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { usePathname, useRouter } from "next/navigation"
import { Feedback } from "@/features/feedback/feedback.type"
import useDeleteFeedback from "@/features/feedback/useDeleteFeedback"
import useListFeedbacks from "@/features/feedback/useListFeedbacks"
import { MoreHorizontal, Trash } from "lucide-react"

import { Button } from "@/components/ui/button"
import {
Expand All @@ -15,6 +14,7 @@ import {
DropdownMenuLabel,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"
import { Icons } from "@/components/custom/icons"
import { AlertModal } from "@/components/modals/alert-modal"

type CellActionProps = {
Expand Down Expand Up @@ -50,13 +50,13 @@ export const CellAction: FC<CellActionProps> = ({ data }) => {
<DropdownMenuTrigger asChild>
<Button variant="ghost" className="h-8 w-8 p-0">
<span className="sr-only">Open menu</span>
<MoreHorizontal className="h-4 w-4" />
<Icons.more className="h-4 w-4" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuLabel>Actions</DropdownMenuLabel>
<DropdownMenuItem onClick={() => setOpen(true)}>
<Trash className="mr-2 h-4 w-4" /> Delete
<Icons.trash className="mr-2 h-4 w-4" /> Delete
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
Expand Down
Loading

0 comments on commit 6e92cb0

Please sign in to comment.