Compare commits
3 Commits
eadfccfc0e
...
798896e4ee
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
798896e4ee | ||
|
|
b00adf89ec | ||
|
|
2c703de8e5 |
@ -9,15 +9,12 @@ const deleteTagsResponseSchema = z.object({
|
||||
}),
|
||||
})
|
||||
|
||||
type TTagsId = Pick<TTagSchema, 'id'>
|
||||
type TParameters = {
|
||||
payload: TTagsId
|
||||
id: TTagSchema['id']
|
||||
} & THttpServer
|
||||
|
||||
export type TDeleteTagsResponse = z.infer<typeof deleteTagsResponseSchema>
|
||||
export const deleteTagsRequest = async (parameters: TParameters) => {
|
||||
const { payload, ...restParameters } = parameters
|
||||
const { id } = payload
|
||||
const { id, ...restParameters } = parameters
|
||||
try {
|
||||
const { data } = await HttpServer(restParameters).delete(
|
||||
`/api/tag/${id}/delete`,
|
||||
|
||||
@ -5,21 +5,21 @@ import {
|
||||
DialogPanel,
|
||||
DialogTitle,
|
||||
} from '@headlessui/react'
|
||||
import { useEffect, type Dispatch, type SetStateAction } from 'react'
|
||||
import { useEffect, type PropsWithChildren } from 'react'
|
||||
import toast from 'react-hot-toast'
|
||||
import { useFetcher } from 'react-router'
|
||||
|
||||
import type { TSubscribePlanResponse } from '~/apis/common/get-subscribe-plan'
|
||||
import { Button } from '~/components/ui/button'
|
||||
import { formatNumberWithPeriods } from '~/utils/formatter'
|
||||
|
||||
type TProperties = {
|
||||
selectedItem?: TSubscribePlanResponse
|
||||
setSelectedItem: Dispatch<SetStateAction<TSubscribePlanResponse | undefined>>
|
||||
type TProperties = PropsWithChildren & {
|
||||
selectedId?: string
|
||||
close: () => void
|
||||
title: string
|
||||
fetcherAction: string
|
||||
}
|
||||
|
||||
export const DialogDelete = (properties: TProperties) => {
|
||||
const { selectedItem, setSelectedItem } = properties || {}
|
||||
const { selectedId, close, children, title, fetcherAction } = properties || {}
|
||||
const fetcher = useFetcher()
|
||||
|
||||
useEffect(() => {
|
||||
@ -29,8 +29,8 @@ export const DialogDelete = (properties: TProperties) => {
|
||||
}
|
||||
|
||||
if (fetcher.data?.success === true) {
|
||||
setSelectedItem(undefined)
|
||||
toast.success('Subscribe plan berhasil dihapus!')
|
||||
close()
|
||||
toast.success(`${title} berhasil dihapus!`)
|
||||
return
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
@ -38,10 +38,10 @@ export const DialogDelete = (properties: TProperties) => {
|
||||
|
||||
return (
|
||||
<Dialog
|
||||
open={!!selectedItem}
|
||||
open={!!selectedId}
|
||||
onClose={() => {
|
||||
if (fetcher.state === 'idle') {
|
||||
setSelectedItem(undefined)
|
||||
close()
|
||||
}
|
||||
}}
|
||||
className="relative z-50"
|
||||
@ -56,20 +56,17 @@ export const DialogDelete = (properties: TProperties) => {
|
||||
transition
|
||||
className="max-w-lg space-y-6 rounded-lg bg-white p-8 duration-300 ease-out data-[closed]:scale-95 data-[closed]:opacity-0 sm:shadow-lg"
|
||||
>
|
||||
<DialogTitle className="relative flex justify-start text-xl font-bold">
|
||||
Anda akan menghapus subscribe plan berikut?
|
||||
<DialogTitle className="relative text-xl font-bold">
|
||||
<span>Anda akan menghapus</span>{' '}
|
||||
<span className="lowercase">{title}</span> <span>berikut?</span>
|
||||
</DialogTitle>
|
||||
<Description className="space-y-1 text-center text-[#565658]">
|
||||
<p>{selectedItem?.name}</p>
|
||||
<p>Length: {selectedItem?.length}</p>
|
||||
<p>
|
||||
Harga: Rp. {formatNumberWithPeriods(selectedItem?.price || 0)}
|
||||
</p>
|
||||
{children}
|
||||
</Description>
|
||||
<div className="flex justify-end">
|
||||
<fetcher.Form
|
||||
method="POST"
|
||||
action={`/actions/admin/subscribe-plan/delete/${selectedItem?.id}`}
|
||||
action={fetcherAction}
|
||||
className="grid"
|
||||
>
|
||||
<Button
|
||||
@ -17,7 +17,7 @@ type ModalProperties = {
|
||||
description?: string
|
||||
}
|
||||
|
||||
export const PopupModal = ({
|
||||
export const DialogNews = ({
|
||||
isOpen,
|
||||
onClose,
|
||||
children,
|
||||
@ -33,7 +33,7 @@ const DESCRIPTIONS: DescriptionMap = {
|
||||
error: 'Terjadi kesalahan. Silakan coba lagi.',
|
||||
}
|
||||
|
||||
export const SuccessModal = ({ isOpen, onClose }: ModalProperties) => {
|
||||
export const DialogSuccess = ({ isOpen, onClose }: ModalProperties) => {
|
||||
const { setIsLoginOpen, setIsSubscribeOpen } = useNewsContext()
|
||||
const loaderData = useRouteLoaderData<typeof loader>('routes/_news')
|
||||
const { userData } = loaderData || {}
|
||||
@ -8,22 +8,16 @@ import TextStyle from '@tiptap/extension-text-style'
|
||||
import { EditorContent, useEditor } from '@tiptap/react'
|
||||
import StarterKit from '@tiptap/starter-kit'
|
||||
import { useEffect, useId, useState } from 'react'
|
||||
import {
|
||||
get,
|
||||
type FieldError,
|
||||
type FieldValues,
|
||||
type Path,
|
||||
type RegisterOptions,
|
||||
} from 'react-hook-form'
|
||||
import { get, type FieldError, type RegisterOptions } from 'react-hook-form'
|
||||
import { useRemixFormContext } from 'remix-hook-form'
|
||||
import { twMerge } from 'tailwind-merge'
|
||||
|
||||
import { EditorMenuBar } from './editor-menubar'
|
||||
import { EditorTextArea } from './editor-textarea'
|
||||
|
||||
type TProperties<TFormValues extends FieldValues> = {
|
||||
type TProperties = {
|
||||
id?: string
|
||||
name: Path<TFormValues>
|
||||
name: string
|
||||
label?: string
|
||||
placeholder?: string
|
||||
labelClassName?: string
|
||||
@ -36,9 +30,7 @@ type TProperties<TFormValues extends FieldValues> = {
|
||||
category: string
|
||||
}
|
||||
|
||||
export const TextEditor = <TFormValues extends Record<string, unknown>>(
|
||||
properties: TProperties<TFormValues>,
|
||||
) => {
|
||||
export const TextEditor = (properties: TProperties) => {
|
||||
const {
|
||||
id,
|
||||
label,
|
||||
@ -92,7 +84,7 @@ export const TextEditor = <TFormValues extends Record<string, unknown>>(
|
||||
immediatelyRender: false,
|
||||
content: watchContent,
|
||||
onUpdate: ({ editor }) => {
|
||||
setValue(name, editor.getHTML() as any) // eslint-disable-line @typescript-eslint/no-explicit-any
|
||||
setValue(name, editor.getHTML() as string)
|
||||
},
|
||||
})
|
||||
useEffect(() => {
|
||||
|
||||
@ -7,7 +7,7 @@ import {
|
||||
type SetStateAction,
|
||||
} from 'react'
|
||||
|
||||
import type { ModalProperties } from '~/components/popup/success-modal'
|
||||
import type { ModalProperties } from '~/components/dialog/success'
|
||||
|
||||
type NewsContextProperties = {
|
||||
isLoginOpen: boolean
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import { type PropsWithChildren } from 'react'
|
||||
import { Toaster } from 'react-hot-toast'
|
||||
|
||||
import { PopupModal } from '~/components/popup/modal'
|
||||
import { SuccessModal } from '~/components/popup/success-modal'
|
||||
import { DialogNews } from '~/components/dialog/news'
|
||||
import { DialogSuccess } from '~/components/dialog/success'
|
||||
import { useNewsContext } from '~/contexts/news'
|
||||
import { Banner } from '~/layouts/news/banner'
|
||||
import { FormForgotPassword } from '~/layouts/news/form-forgot-password'
|
||||
@ -47,39 +47,39 @@ export const NewsDefaultLayout = (properties: PropsWithChildren) => {
|
||||
|
||||
<Toaster />
|
||||
|
||||
<PopupModal
|
||||
<DialogNews
|
||||
isOpen={isLoginOpen}
|
||||
onClose={() => setIsLoginOpen(false)}
|
||||
description="Selamat Datang, silakan daftarkan akun Anda untuk melanjutkan!"
|
||||
>
|
||||
<FormLogin />
|
||||
</PopupModal>
|
||||
</DialogNews>
|
||||
|
||||
<PopupModal
|
||||
<DialogNews
|
||||
isOpen={isRegisterOpen}
|
||||
onClose={() => setIsRegisterOpen(false)}
|
||||
description="Selamat Datang, silakan isi keterangan akun Anda untuk melanjutkan!"
|
||||
>
|
||||
<FormRegister />
|
||||
</PopupModal>
|
||||
</DialogNews>
|
||||
|
||||
<PopupModal
|
||||
<DialogNews
|
||||
isOpen={isForgetOpen}
|
||||
onClose={() => setIsForgetOpen(false)}
|
||||
description="Selamat Datang, silakan isi keterangan akun Anda untuk melanjutkan!"
|
||||
>
|
||||
<FormForgotPassword />
|
||||
</PopupModal>
|
||||
</DialogNews>
|
||||
|
||||
<PopupModal
|
||||
<DialogNews
|
||||
isOpen={isSubscribeOpen}
|
||||
onClose={() => setIsSubscribeOpen(false)}
|
||||
description="Selamat Datang, silakan Pilih Subscribe Plan Anda untuk melanjutkan!"
|
||||
>
|
||||
<FormSubscribePlan />
|
||||
</PopupModal>
|
||||
</DialogNews>
|
||||
|
||||
<SuccessModal
|
||||
<DialogSuccess
|
||||
isOpen={isSuccessOpen}
|
||||
onClose={() => {
|
||||
setIsSuccessOpen(undefined)
|
||||
|
||||
@ -1,97 +0,0 @@
|
||||
import {
|
||||
Description,
|
||||
Dialog,
|
||||
DialogBackdrop,
|
||||
DialogPanel,
|
||||
DialogTitle,
|
||||
} from '@headlessui/react'
|
||||
import { useEffect, type Dispatch, type SetStateAction } from 'react'
|
||||
import toast from 'react-hot-toast'
|
||||
import { Link, useFetcher } from 'react-router'
|
||||
|
||||
import type { TAdResponse } from '~/apis/common/get-ads'
|
||||
import { Button } from '~/components/ui/button'
|
||||
|
||||
type TProperties = {
|
||||
selectedItem?: TAdResponse
|
||||
setSelectedItem: Dispatch<SetStateAction<TAdResponse | undefined>>
|
||||
}
|
||||
|
||||
export const DialogDelete = (properties: TProperties) => {
|
||||
const { selectedItem, setSelectedItem } = properties || {}
|
||||
const fetcher = useFetcher()
|
||||
|
||||
useEffect(() => {
|
||||
if (fetcher.data?.success === false) {
|
||||
toast.error(fetcher.data?.message)
|
||||
return
|
||||
}
|
||||
|
||||
if (fetcher.data?.success === true) {
|
||||
setSelectedItem(undefined)
|
||||
toast.success('Banner iklan berhasil dihapus!')
|
||||
return
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [fetcher.data])
|
||||
|
||||
return (
|
||||
<Dialog
|
||||
open={!!selectedItem}
|
||||
onClose={() => {
|
||||
if (fetcher.state === 'idle') {
|
||||
setSelectedItem(undefined)
|
||||
}
|
||||
}}
|
||||
className="relative z-50"
|
||||
transition
|
||||
>
|
||||
<DialogBackdrop
|
||||
className="fixed inset-0 bg-black/50 duration-300 ease-out data-[closed]:opacity-0"
|
||||
transition
|
||||
/>
|
||||
<div className="fixed inset-0 flex w-screen justify-center overflow-y-auto p-0 max-sm:bg-white sm:items-center sm:p-4">
|
||||
<DialogPanel
|
||||
transition
|
||||
className="max-w-lg space-y-6 rounded-lg bg-white p-8 duration-300 ease-out data-[closed]:scale-95 data-[closed]:opacity-0 sm:shadow-lg"
|
||||
>
|
||||
<DialogTitle className="relative flex justify-start text-xl font-bold">
|
||||
Anda akan menghapus banner berikut?
|
||||
</DialogTitle>
|
||||
<Description className="space-y-1 text-center text-[#565658]">
|
||||
<img
|
||||
src={selectedItem?.image_url}
|
||||
alt={selectedItem?.image_url}
|
||||
className="aspect-[150/1] h-[50px] rounded object-contain"
|
||||
/>
|
||||
<Button
|
||||
as={Link}
|
||||
to={selectedItem?.url || ''}
|
||||
variant="link"
|
||||
size="fit"
|
||||
>
|
||||
{selectedItem?.url}
|
||||
</Button>
|
||||
</Description>
|
||||
<div className="flex justify-end">
|
||||
<fetcher.Form
|
||||
method="POST"
|
||||
action={`/actions/admin/advertisements/delete/${selectedItem?.id}`}
|
||||
className="grid"
|
||||
>
|
||||
<Button
|
||||
type="submit"
|
||||
variant="newsDanger"
|
||||
className="text-md h-[42px] rounded-md"
|
||||
disabled={fetcher.state !== 'idle'}
|
||||
isLoading={fetcher.state !== 'idle'}
|
||||
>
|
||||
Hapus
|
||||
</Button>
|
||||
</fetcher.Form>
|
||||
</div>
|
||||
</DialogPanel>
|
||||
</div>
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
@ -9,13 +9,12 @@ import { useState } from 'react'
|
||||
import { Link, useRouteLoaderData } from 'react-router'
|
||||
|
||||
import type { TAdResponse } from '~/apis/common/get-ads'
|
||||
import { DialogDelete } from '~/components/dialog/delete'
|
||||
import { Button } from '~/components/ui/button'
|
||||
import { UiTable } from '~/components/ui/table'
|
||||
import { TitleDashboard } from '~/components/ui/title-dashboard'
|
||||
import type { loader } from '~/routes/_admin.lg-admin._dashboard.advertisements._index'
|
||||
|
||||
import { DialogDelete } from './dialog-delete'
|
||||
|
||||
export const AdvertisementsPage = () => {
|
||||
const loaderData = useRouteLoaderData<typeof loader>(
|
||||
'routes/_admin.lg-admin._dashboard.advertisements._index',
|
||||
@ -99,9 +98,25 @@ export const AdvertisementsPage = () => {
|
||||
/>
|
||||
|
||||
<DialogDelete
|
||||
selectedItem={selectedAds}
|
||||
setSelectedItem={setSelectedAds}
|
||||
/>
|
||||
selectedId={selectedAds?.id}
|
||||
close={() => setSelectedAds(undefined)}
|
||||
title="Banner iklan"
|
||||
fetcherAction={`/actions/admin/advertisements/delete/${selectedAds?.id}`}
|
||||
>
|
||||
<img
|
||||
src={selectedAds?.image_url}
|
||||
alt={selectedAds?.image_url}
|
||||
className="aspect-[150/1] h-[50px] rounded object-contain"
|
||||
/>
|
||||
<Button
|
||||
as={Link}
|
||||
to={selectedAds?.url || ''}
|
||||
variant="link"
|
||||
size="fit"
|
||||
>
|
||||
{selectedAds?.url}
|
||||
</Button>
|
||||
</DialogDelete>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@ -9,6 +9,7 @@ import { useState } from 'react'
|
||||
import { Link, useRouteLoaderData } from 'react-router'
|
||||
|
||||
import type { TSubscribePlanResponse } from '~/apis/common/get-subscribe-plan'
|
||||
import { DialogDelete } from '~/components/dialog/delete'
|
||||
import { Button } from '~/components/ui/button'
|
||||
import { getStatusBadge, type TColorBadge } from '~/components/ui/color-badge'
|
||||
import { UiTable } from '~/components/ui/table'
|
||||
@ -16,8 +17,6 @@ import { TitleDashboard } from '~/components/ui/title-dashboard'
|
||||
import type { loader } from '~/routes/_admin.lg-admin._dashboard.subscribe-plan._index'
|
||||
import { formatNumberWithPeriods } from '~/utils/formatter'
|
||||
|
||||
import { DialogDelete } from './dialog-delete'
|
||||
|
||||
export const SubscribePlanPage = () => {
|
||||
const loaderData = useRouteLoaderData<typeof loader>(
|
||||
'routes/_admin.lg-admin._dashboard.subscribe-plan._index',
|
||||
@ -130,9 +129,18 @@ export const SubscribePlanPage = () => {
|
||||
/>
|
||||
|
||||
<DialogDelete
|
||||
selectedItem={selectedSubscribePlan}
|
||||
setSelectedItem={setSelectedSubscribePlan}
|
||||
/>
|
||||
selectedId={selectedSubscribePlan?.id}
|
||||
close={() => setSelectedSubscribePlan(undefined)}
|
||||
title="Subscribe plan"
|
||||
fetcherAction={`/actions/admin/subscribe-plan/delete/${selectedSubscribePlan?.id}`}
|
||||
>
|
||||
<p>{selectedSubscribePlan?.name}</p>
|
||||
<p>Length: {selectedSubscribePlan?.length}</p>
|
||||
<p>
|
||||
Harga: Rp.{' '}
|
||||
{formatNumberWithPeriods(selectedSubscribePlan?.price || 0)}
|
||||
</p>
|
||||
</DialogDelete>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@ -1,7 +1,15 @@
|
||||
import {
|
||||
PencilSquareIcon,
|
||||
PlusIcon,
|
||||
TrashIcon,
|
||||
} from '@heroicons/react/20/solid'
|
||||
import DT, { type Config, type ConfigColumns } from 'datatables.net-dt'
|
||||
import DataTable, { type DataTableSlots } from 'datatables.net-react'
|
||||
import { useState } from 'react'
|
||||
import { Link, useRouteLoaderData } from 'react-router'
|
||||
|
||||
import type { TTagResponse } from '~/apis/common/get-tags'
|
||||
import { DialogDelete } from '~/components/dialog/delete'
|
||||
import { Button } from '~/components/ui/button'
|
||||
import { UiTable } from '~/components/ui/table'
|
||||
import { TitleDashboard } from '~/components/ui/title-dashboard'
|
||||
@ -11,6 +19,7 @@ export const TagsPage = () => {
|
||||
const loaderData = useRouteLoaderData<typeof loader>(
|
||||
'routes/_admin.lg-admin._dashboard',
|
||||
)
|
||||
const [selectedTag, setSelectedTag] = useState<TTagResponse>()
|
||||
const { tagsData: dataTable } = loaderData || {}
|
||||
|
||||
DataTable.use(DT)
|
||||
@ -40,15 +49,26 @@ export const TagsPage = () => {
|
||||
},
|
||||
]
|
||||
const dataSlot: DataTableSlots = {
|
||||
3: (value: string) => (
|
||||
<Button
|
||||
as="a"
|
||||
href={`/lg-admin/tags/update/${value}`}
|
||||
className="text-md rounded-md"
|
||||
size="sm"
|
||||
>
|
||||
Update Tag
|
||||
</Button>
|
||||
3: (value: string, _type: unknown, data: TTagResponse) => (
|
||||
<div className="flex space-x-2">
|
||||
<Button
|
||||
as="a"
|
||||
href={`/lg-admin/tags/update/${value}`}
|
||||
size="icon"
|
||||
title="Update Tag"
|
||||
>
|
||||
<PencilSquareIcon className="h-4 w-4" />
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
size="icon"
|
||||
variant="newsDanger"
|
||||
onClick={() => setSelectedTag(data)}
|
||||
title="Hapus Tag"
|
||||
>
|
||||
<TrashIcon className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
),
|
||||
}
|
||||
const dataOptions: Config = {
|
||||
@ -69,7 +89,7 @@ export const TagsPage = () => {
|
||||
size="lg"
|
||||
className="text-md h-[42px] px-4"
|
||||
>
|
||||
Buat Tag
|
||||
<PlusIcon className="h-8 w-8" /> Buat Tag
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
@ -80,6 +100,15 @@ export const TagsPage = () => {
|
||||
slots={dataSlot}
|
||||
title="Daftar Tags"
|
||||
/>
|
||||
|
||||
<DialogDelete
|
||||
selectedId={selectedTag?.id}
|
||||
close={() => setSelectedTag(undefined)}
|
||||
title="Tag"
|
||||
fetcherAction={`/actions/admin/tags/delete/${selectedTag?.id}`}
|
||||
>
|
||||
<p>{selectedTag?.name}</p>
|
||||
</DialogDelete>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
48
app/routes/actions.admin.tags.delete.$id.ts
Normal file
48
app/routes/actions.admin.tags.delete.$id.ts
Normal file
@ -0,0 +1,48 @@
|
||||
import { data } from 'react-router'
|
||||
import { XiorError } from 'xior'
|
||||
|
||||
import { deleteTagsRequest } from '~/apis/admin/delete-tags'
|
||||
import { handleCookie } from '~/libs/cookies'
|
||||
|
||||
import type { Route } from './+types/actions.admin.advertisements.create'
|
||||
|
||||
export const action = async ({ request, params }: Route.ActionArgs) => {
|
||||
const { staffToken: accessToken } = await handleCookie(request)
|
||||
const { id } = params
|
||||
try {
|
||||
const { data: tagData } = await deleteTagsRequest({
|
||||
accessToken,
|
||||
id,
|
||||
})
|
||||
|
||||
return data(
|
||||
{
|
||||
success: true,
|
||||
tagData,
|
||||
},
|
||||
{
|
||||
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