Compare commits
4 Commits
798896e4ee
...
01f9cf06ca
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
01f9cf06ca | ||
|
|
ff51941647 | ||
|
|
8a9cacf7b4 | ||
|
|
c89731e124 |
27
app/apis/admin/delete-categories.ts
Normal file
27
app/apis/admin/delete-categories.ts
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import { z } from 'zod'
|
||||||
|
|
||||||
|
import { HttpServer, type THttpServer } from '~/libs/http-server'
|
||||||
|
import type { TCategorySchema } from '~/pages/form-category'
|
||||||
|
|
||||||
|
const deleteCategoriesResponseSchema = z.object({
|
||||||
|
data: z.object({
|
||||||
|
Message: z.string(),
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
|
||||||
|
type TParameters = {
|
||||||
|
id: TCategorySchema['id']
|
||||||
|
} & THttpServer
|
||||||
|
|
||||||
|
export const deleteCategoriesRequest = async (parameters: TParameters) => {
|
||||||
|
const { id, ...restParameters } = parameters
|
||||||
|
try {
|
||||||
|
const { data } = await HttpServer(restParameters).delete(
|
||||||
|
`/api/category/${id}/delete`,
|
||||||
|
)
|
||||||
|
return deleteCategoriesResponseSchema.parse(data)
|
||||||
|
} catch (error) {
|
||||||
|
// eslint-disable-next-line unicorn/no-useless-promise-resolve-reject
|
||||||
|
return Promise.reject(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -12,7 +12,7 @@ const userResponseSchema = z.object({
|
|||||||
subscribe_plan_id: z.string(),
|
subscribe_plan_id: z.string(),
|
||||||
start_date: z.string(),
|
start_date: z.string(),
|
||||||
end_date: z.string().nullable(),
|
end_date: z.string().nullable(),
|
||||||
status: z.string(),
|
status: z.number(),
|
||||||
auto_renew: z.boolean(),
|
auto_renew: z.boolean(),
|
||||||
subscribe_plan: z.object({
|
subscribe_plan: z.object({
|
||||||
id: z.string(),
|
id: z.string(),
|
||||||
|
|||||||
69
app/components/ui/table-search.tsx
Normal file
69
app/components/ui/table-search.tsx
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
import { Field, Input, Label, Select } from '@headlessui/react'
|
||||||
|
import { MagnifyingGlassIcon } from '@heroicons/react/20/solid'
|
||||||
|
import { useState } from 'react'
|
||||||
|
|
||||||
|
interface SearchFilterProperties {
|
||||||
|
title: string
|
||||||
|
columns?: string[]
|
||||||
|
onSearch: (value: string) => void
|
||||||
|
onStatusFilter?: (value: string) => Promise<void>
|
||||||
|
}
|
||||||
|
export const TableSearchFilter: React.FC<SearchFilterProperties> = ({
|
||||||
|
onSearch,
|
||||||
|
onStatusFilter,
|
||||||
|
title,
|
||||||
|
}: SearchFilterProperties) => {
|
||||||
|
const [searchTerm, setSearchTerm] = useState<string>('')
|
||||||
|
const [statusFilter, setStatusFilter] = useState<string>('')
|
||||||
|
|
||||||
|
const handleSearch = (searchValue: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
setSearchTerm(searchValue.target.value)
|
||||||
|
onSearch(searchValue.target.value)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleStatusFilter = (
|
||||||
|
searchValue: React.ChangeEvent<HTMLSelectElement>,
|
||||||
|
) => {
|
||||||
|
setStatusFilter(searchValue.target.value)
|
||||||
|
onStatusFilter?.(searchValue.target.value)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex items-center gap-5 rounded-lg bg-gray-50 text-[#363636]">
|
||||||
|
<div className="w-[400px]">
|
||||||
|
<Field>
|
||||||
|
<Label className="mb-2 block text-sm font-medium">Cari {title}</Label>
|
||||||
|
<div className="relative">
|
||||||
|
<Input
|
||||||
|
type="text"
|
||||||
|
value={searchTerm}
|
||||||
|
onChange={handleSearch}
|
||||||
|
placeholder={`Cari Nama ${title}`}
|
||||||
|
className="w-full rounded-lg bg-white p-2 pr-10 pl-4 shadow focus:ring-1 focus:ring-[#2E2F7C] focus:outline-none"
|
||||||
|
/>
|
||||||
|
<div className="absolute inset-y-0 right-0 flex items-center pr-3">
|
||||||
|
<MagnifyingGlassIcon className="h-5 w-5 text-[#363636]" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Field>
|
||||||
|
</div>
|
||||||
|
{onStatusFilter && (
|
||||||
|
// will handel if filter have dropdown status
|
||||||
|
<div className="w-[235px]">
|
||||||
|
<Field>
|
||||||
|
<Label className="mb-2 block text-sm font-medium">Status</Label>
|
||||||
|
<Select
|
||||||
|
value={statusFilter}
|
||||||
|
onChange={handleStatusFilter}
|
||||||
|
className="w-full rounded-lg bg-white p-2 shadow focus:ring-1 focus:ring-[#2E2F7C] focus:outline-none"
|
||||||
|
>
|
||||||
|
<option>Pilih Status</option>
|
||||||
|
<option>Aktif</option>
|
||||||
|
<option>Nonaktif</option>
|
||||||
|
</Select>
|
||||||
|
</Field>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@ -32,9 +32,9 @@ export const UiTable: React.FC<UiTableProperties> = ({
|
|||||||
thead.classList.add('text-left')
|
thead.classList.add('text-left')
|
||||||
},
|
},
|
||||||
paging: true,
|
paging: true,
|
||||||
searching: true,
|
searching: false,
|
||||||
ordering: true,
|
ordering: true,
|
||||||
info: true,
|
info: false,
|
||||||
language: {
|
language: {
|
||||||
paginate: {
|
paginate: {
|
||||||
first: renderPaginationIcon(
|
first: renderPaginationIcon(
|
||||||
|
|||||||
@ -1,8 +1,11 @@
|
|||||||
|
import { PencilSquareIcon, TrashIcon } from '@heroicons/react/20/solid'
|
||||||
import DT, { type Config, type ConfigColumns } from 'datatables.net-dt'
|
import DT, { type Config, type ConfigColumns } from 'datatables.net-dt'
|
||||||
import DataTable, { type DataTableSlots } from 'datatables.net-react'
|
import DataTable, { type DataTableSlots } from 'datatables.net-react'
|
||||||
|
import { useState } from 'react'
|
||||||
import { Link, useRouteLoaderData } from 'react-router'
|
import { Link, useRouteLoaderData } from 'react-router'
|
||||||
|
|
||||||
import type { TCategoryResponse } from '~/apis/common/get-categories'
|
import type { TCategoryResponse } from '~/apis/common/get-categories'
|
||||||
|
import { DialogDelete } from '~/components/dialog/delete'
|
||||||
import { Button } from '~/components/ui/button'
|
import { Button } from '~/components/ui/button'
|
||||||
import { UiTable } from '~/components/ui/table'
|
import { UiTable } from '~/components/ui/table'
|
||||||
import { TitleDashboard } from '~/components/ui/title-dashboard'
|
import { TitleDashboard } from '~/components/ui/title-dashboard'
|
||||||
@ -12,7 +15,7 @@ export const CategoriesPage = () => {
|
|||||||
const loaderData = useRouteLoaderData<typeof loader>(
|
const loaderData = useRouteLoaderData<typeof loader>(
|
||||||
'routes/_admin.lg-admin._dashboard',
|
'routes/_admin.lg-admin._dashboard',
|
||||||
)
|
)
|
||||||
|
const [selectedCategory, setSelectedCategory] = useState<TCategoryResponse>()
|
||||||
DataTable.use(DT)
|
DataTable.use(DT)
|
||||||
const dataTable =
|
const dataTable =
|
||||||
loaderData?.categoriesData?.sort((a, b) => {
|
loaderData?.categoriesData?.sort((a, b) => {
|
||||||
@ -55,15 +58,30 @@ export const CategoriesPage = () => {
|
|||||||
<pre className="text-sm text-[#7C7C7C]">Kode: {data.code}</pre>
|
<pre className="text-sm text-[#7C7C7C]">Kode: {data.code}</pre>
|
||||||
</div>
|
</div>
|
||||||
),
|
),
|
||||||
3: (value: string) => (
|
3: (value: string, _type: unknown, data: TCategoryResponse) => (
|
||||||
|
<div className="flex space-x-2">
|
||||||
<Button
|
<Button
|
||||||
as="a"
|
as="a"
|
||||||
href={`/lg-admin/categories/update/${value}`}
|
href={`/lg-admin/categories/update/${value}`}
|
||||||
className="text-md rounded-md"
|
size="icon"
|
||||||
size="sm"
|
title="Update Kategori"
|
||||||
>
|
>
|
||||||
Update Kategori
|
<PencilSquareIcon className="h-4 w-4" />
|
||||||
</Button>
|
</Button>
|
||||||
|
{data.code === 'spotlight' ? (
|
||||||
|
''
|
||||||
|
) : (
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
size="icon"
|
||||||
|
variant="newsDanger"
|
||||||
|
onClick={() => setSelectedCategory(data)}
|
||||||
|
title="Hapus Kategori"
|
||||||
|
>
|
||||||
|
<TrashIcon className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
const dataOptions: Config = {
|
const dataOptions: Config = {
|
||||||
@ -95,6 +113,15 @@ export const CategoriesPage = () => {
|
|||||||
slots={dataSlot}
|
slots={dataSlot}
|
||||||
title="Daftar Kategori"
|
title="Daftar Kategori"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<DialogDelete
|
||||||
|
selectedId={selectedCategory?.id}
|
||||||
|
close={() => setSelectedCategory(undefined)}
|
||||||
|
title="Kategori"
|
||||||
|
fetcherAction={`/actions/admin/categories/delete/${selectedCategory?.id}`}
|
||||||
|
>
|
||||||
|
<p>{selectedCategory?.name}</p>
|
||||||
|
</DialogDelete>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,6 +12,7 @@ import type { TTagResponse } from '~/apis/common/get-tags'
|
|||||||
import { DialogDelete } from '~/components/dialog/delete'
|
import { DialogDelete } from '~/components/dialog/delete'
|
||||||
import { Button } from '~/components/ui/button'
|
import { Button } from '~/components/ui/button'
|
||||||
import { UiTable } from '~/components/ui/table'
|
import { UiTable } from '~/components/ui/table'
|
||||||
|
import { TableSearchFilter } from '~/components/ui/table-search'
|
||||||
import { TitleDashboard } from '~/components/ui/title-dashboard'
|
import { TitleDashboard } from '~/components/ui/title-dashboard'
|
||||||
import type { loader } from '~/routes/_admin.lg-admin._dashboard'
|
import type { loader } from '~/routes/_admin.lg-admin._dashboard'
|
||||||
|
|
||||||
@ -19,6 +20,7 @@ export const TagsPage = () => {
|
|||||||
const loaderData = useRouteLoaderData<typeof loader>(
|
const loaderData = useRouteLoaderData<typeof loader>(
|
||||||
'routes/_admin.lg-admin._dashboard',
|
'routes/_admin.lg-admin._dashboard',
|
||||||
)
|
)
|
||||||
|
const [searchTerm, setSearchTerm] = useState<string>('')
|
||||||
const [selectedTag, setSelectedTag] = useState<TTagResponse>()
|
const [selectedTag, setSelectedTag] = useState<TTagResponse>()
|
||||||
const { tagsData: dataTable } = loaderData || {}
|
const { tagsData: dataTable } = loaderData || {}
|
||||||
|
|
||||||
@ -73,16 +75,27 @@ export const TagsPage = () => {
|
|||||||
}
|
}
|
||||||
const dataOptions: Config = {
|
const dataOptions: Config = {
|
||||||
paging: true,
|
paging: true,
|
||||||
searching: true,
|
|
||||||
ordering: true,
|
|
||||||
info: true,
|
info: true,
|
||||||
}
|
}
|
||||||
|
const filteredData = dataTable?.filter((item) => {
|
||||||
|
const matchesSearch = Object.keys(item).some((key) =>
|
||||||
|
item[key as keyof TTagResponse]
|
||||||
|
?.toString()
|
||||||
|
.toLowerCase()
|
||||||
|
.includes(searchTerm.toLowerCase()),
|
||||||
|
)
|
||||||
|
return matchesSearch
|
||||||
|
})
|
||||||
return (
|
return (
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
<TitleDashboard title="Tags" />
|
<TitleDashboard title="Tags" />
|
||||||
<div className="mb-8 flex items-end justify-between gap-5">
|
<div className="mb-8 flex items-end justify-between gap-5">
|
||||||
<div className="flex-1">{/* TODO: Filter */}</div>
|
<div className="flex-1">
|
||||||
|
<TableSearchFilter
|
||||||
|
onSearch={setSearchTerm}
|
||||||
|
title="Tag"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
<Button
|
<Button
|
||||||
as={Link}
|
as={Link}
|
||||||
to="/lg-admin/tags/create"
|
to="/lg-admin/tags/create"
|
||||||
@ -94,7 +107,7 @@ export const TagsPage = () => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<UiTable
|
<UiTable
|
||||||
data={dataTable || []}
|
data={filteredData || []}
|
||||||
columns={dataColumns}
|
columns={dataColumns}
|
||||||
options={dataOptions}
|
options={dataOptions}
|
||||||
slots={dataSlot}
|
slots={dataSlot}
|
||||||
|
|||||||
48
app/routes/actions.admin.categories.delete.$id.ts
Normal file
48
app/routes/actions.admin.categories.delete.$id.ts
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
import { data } from 'react-router'
|
||||||
|
import { XiorError } from 'xior'
|
||||||
|
|
||||||
|
import { deleteCategoriesRequest } from '~/apis/admin/delete-categories'
|
||||||
|
import { handleCookie } from '~/libs/cookies'
|
||||||
|
|
||||||
|
import type { Route } from './+types/actions.admin.categories.delete.$id'
|
||||||
|
|
||||||
|
export const action = async ({ request, params }: Route.ActionArgs) => {
|
||||||
|
const { staffToken: accessToken } = await handleCookie(request)
|
||||||
|
const { id } = params
|
||||||
|
try {
|
||||||
|
const { data: categoryData } = await deleteCategoriesRequest({
|
||||||
|
accessToken,
|
||||||
|
id,
|
||||||
|
})
|
||||||
|
|
||||||
|
return data(
|
||||||
|
{
|
||||||
|
success: true,
|
||||||
|
categoryData,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
status: 200,
|
||||||
|
statusText: 'OK',
|
||||||
|
},
|
||||||
|
)
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof XiorError) {
|
||||||
|
return data(
|
||||||
|
{
|
||||||
|
success: false,
|
||||||
|
message: error?.response?.data?.error?.message || error.message,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
status: error?.response?.status || 500,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return data(
|
||||||
|
{
|
||||||
|
success: false,
|
||||||
|
message: 'Internal server error',
|
||||||
|
},
|
||||||
|
{ status: 500 },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user