Compare commits
5 Commits
2e13e11673
...
54a8a97c09
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
54a8a97c09 | ||
|
|
169f0166b8 | ||
|
|
e93c0a8464 | ||
|
|
ba83a6a025 | ||
|
|
c70aa86be6 |
@ -14,7 +14,9 @@ type TParameters = {
|
|||||||
export const getNewsBySlug = async (parameters: TParameters) => {
|
export const getNewsBySlug = async (parameters: TParameters) => {
|
||||||
const { slug, ...restParameters } = parameters
|
const { slug, ...restParameters } = parameters
|
||||||
try {
|
try {
|
||||||
const { data } = await HttpServer(restParameters).get(`/api/news/${slug}`)
|
const { data } = await HttpServer(restParameters).get(
|
||||||
|
`/api/news/${encodeURIComponent(slug)}`,
|
||||||
|
)
|
||||||
return dataResponseSchema.parse(data)
|
return dataResponseSchema.parse(data)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// eslint-disable-next-line unicorn/no-useless-promise-resolve-reject
|
// eslint-disable-next-line unicorn/no-useless-promise-resolve-reject
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import { Input } from '@headlessui/react'
|
||||||
import {
|
import {
|
||||||
ArrowUturnLeftIcon,
|
ArrowUturnLeftIcon,
|
||||||
ArrowUturnRightIcon,
|
ArrowUturnRightIcon,
|
||||||
@ -6,6 +7,7 @@ import {
|
|||||||
Bars3Icon,
|
Bars3Icon,
|
||||||
Bars4Icon,
|
Bars4Icon,
|
||||||
BoldIcon,
|
BoldIcon,
|
||||||
|
CloudArrowUpIcon,
|
||||||
CodeBracketIcon,
|
CodeBracketIcon,
|
||||||
DocumentTextIcon,
|
DocumentTextIcon,
|
||||||
H1Icon,
|
H1Icon,
|
||||||
@ -27,9 +29,12 @@ import {
|
|||||||
useState,
|
useState,
|
||||||
useRef,
|
useRef,
|
||||||
useCallback,
|
useCallback,
|
||||||
|
useEffect,
|
||||||
} from 'react'
|
} from 'react'
|
||||||
import { HexColorInput, HexColorPicker } from 'react-colorful'
|
import { HexColorInput, HexColorPicker } from 'react-colorful'
|
||||||
|
|
||||||
|
import { Button } from '~/components/ui/button'
|
||||||
|
import { useAdminContext } from '~/contexts/admin'
|
||||||
import { useClickOutside } from '~/hooks/use-click-outside'
|
import { useClickOutside } from '~/hooks/use-click-outside'
|
||||||
import { isHexCompatible, rgbToHex } from '~/utils/color'
|
import { isHexCompatible, rgbToHex } from '~/utils/color'
|
||||||
|
|
||||||
@ -43,16 +48,30 @@ type TProperties = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const EditorMenuBar = (properties: TProperties) => {
|
export const EditorMenuBar = (properties: TProperties) => {
|
||||||
const {
|
const { editor, setIsPlainHTML, category, disabled = false } = properties
|
||||||
editor,
|
const { setIsUploadOpen, uploadedFile, setUploadedFile, isUploadOpen } =
|
||||||
setIsPlainHTML,
|
useAdminContext()
|
||||||
// category,
|
const [isOpenImage, setIsOpenImage] = useState(false)
|
||||||
disabled = false,
|
const [imageUrl, setImageUrl] = useState('')
|
||||||
} = properties
|
|
||||||
// const [isOpenImage, setIsOpenImage] = useState(false)
|
|
||||||
const [isOpenColor, setIsOpenColor] = useState(false)
|
const [isOpenColor, setIsOpenColor] = useState(false)
|
||||||
const popover = useRef<HTMLDivElement>(null)
|
const popover = useRef<HTMLDivElement>(null)
|
||||||
const close = useCallback(() => setIsOpenColor(false), [])
|
const close = useCallback(() => {
|
||||||
|
setIsOpenColor(false)
|
||||||
|
setIsOpenImage(false)
|
||||||
|
if (imageUrl) {
|
||||||
|
addImage(imageUrl)
|
||||||
|
}
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (uploadedFile && isUploadOpen === category) {
|
||||||
|
addImage(uploadedFile)
|
||||||
|
setUploadedFile(undefined)
|
||||||
|
setIsUploadOpen(undefined)
|
||||||
|
}
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [uploadedFile])
|
||||||
|
|
||||||
useClickOutside(popover, close)
|
useClickOutside(popover, close)
|
||||||
|
|
||||||
@ -96,167 +115,150 @@ export const EditorMenuBar = (properties: TProperties) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const uploadEnabled = false
|
|
||||||
const toggleUpload = () => {
|
|
||||||
if (uploadEnabled) {
|
|
||||||
// setIsOpenImage(true)
|
|
||||||
} else {
|
|
||||||
const urlImage = globalThis.prompt('URL')
|
|
||||||
if (urlImage) {
|
|
||||||
addImage(urlImage)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<div className="flex items-start justify-between gap-4 px-4 py-3">
|
||||||
<div className="flex items-start justify-between gap-4 px-4 py-3">
|
<div className="flex divide-x">
|
||||||
<div className="flex divide-x">
|
<div className="flex max-w-[150px] flex-wrap items-start gap-1 px-1">
|
||||||
<div className="flex max-w-[150px] flex-wrap items-start gap-1 px-1">
|
<EditorButton
|
||||||
|
onClick={() => editor.chain().focus().toggleBold().run()}
|
||||||
|
disabled={
|
||||||
|
disabled || !editor.can().chain().focus().toggleBold().run()
|
||||||
|
}
|
||||||
|
isActive={editor.isActive('bold')}
|
||||||
|
title="Bold"
|
||||||
|
>
|
||||||
|
<BoldIcon />
|
||||||
|
</EditorButton>
|
||||||
|
<EditorButton
|
||||||
|
onClick={() => editor.chain().focus().toggleItalic().run()}
|
||||||
|
disabled={
|
||||||
|
disabled || !editor.can().chain().focus().toggleItalic().run()
|
||||||
|
}
|
||||||
|
isActive={editor.isActive('italic')}
|
||||||
|
title="Italic"
|
||||||
|
>
|
||||||
|
<ItalicIcon />
|
||||||
|
</EditorButton>
|
||||||
|
<EditorButton
|
||||||
|
onClick={() => editor.chain().focus().toggleStrike().run()}
|
||||||
|
disabled={
|
||||||
|
disabled || !editor.can().chain().focus().toggleStrike().run()
|
||||||
|
}
|
||||||
|
isActive={editor.isActive('strike')}
|
||||||
|
title="Strike"
|
||||||
|
>
|
||||||
|
<StrikethroughIcon />
|
||||||
|
</EditorButton>
|
||||||
|
<div className="relative">
|
||||||
<EditorButton
|
<EditorButton
|
||||||
onClick={() => editor.chain().focus().toggleBold().run()}
|
onClick={() => setIsOpenColor(true)}
|
||||||
disabled={
|
title="Text Color"
|
||||||
disabled || !editor.can().chain().focus().toggleBold().run()
|
style={{
|
||||||
}
|
color: rgbColor,
|
||||||
isActive={editor.isActive('bold')}
|
}}
|
||||||
title="Bold"
|
isActive={true}
|
||||||
|
disabled={disabled}
|
||||||
>
|
>
|
||||||
<BoldIcon />
|
<SwatchIcon />
|
||||||
</EditorButton>
|
</EditorButton>
|
||||||
<EditorButton
|
{isOpenColor && (
|
||||||
onClick={() => editor.chain().focus().toggleItalic().run()}
|
<div
|
||||||
disabled={
|
className="border-md absolute top-8 left-0"
|
||||||
disabled || !editor.can().chain().focus().toggleItalic().run()
|
ref={popover}
|
||||||
}
|
|
||||||
isActive={editor.isActive('italic')}
|
|
||||||
title="Italic"
|
|
||||||
>
|
|
||||||
<ItalicIcon />
|
|
||||||
</EditorButton>
|
|
||||||
<EditorButton
|
|
||||||
onClick={() => editor.chain().focus().toggleStrike().run()}
|
|
||||||
disabled={
|
|
||||||
disabled || !editor.can().chain().focus().toggleStrike().run()
|
|
||||||
}
|
|
||||||
isActive={editor.isActive('strike')}
|
|
||||||
title="Strike"
|
|
||||||
>
|
|
||||||
<StrikethroughIcon />
|
|
||||||
</EditorButton>
|
|
||||||
<div className="relative">
|
|
||||||
<EditorButton
|
|
||||||
onClick={() => setIsOpenColor(true)}
|
|
||||||
title="Text Color"
|
|
||||||
style={{
|
|
||||||
color: rgbColor,
|
|
||||||
}}
|
|
||||||
isActive={true}
|
|
||||||
disabled={disabled}
|
|
||||||
>
|
>
|
||||||
<SwatchIcon />
|
<HexColorPicker
|
||||||
</EditorButton>
|
className="z-10 rounded-lg shadow"
|
||||||
{isOpenColor && (
|
color={rgbColor}
|
||||||
<div
|
onChange={handleChangeColor}
|
||||||
className="border-md absolute top-8 left-0"
|
/>
|
||||||
ref={popover}
|
<div className="">
|
||||||
>
|
<HexColorInput
|
||||||
<HexColorPicker
|
|
||||||
className="z-10"
|
|
||||||
color={rgbColor}
|
color={rgbColor}
|
||||||
onChange={handleChangeColor}
|
onChange={handleChangeColor}
|
||||||
|
prefixed
|
||||||
|
className="relative z-10 mt-1 flex w-full rounded-lg border-0 bg-white px-3 py-2 text-sm shadow read-only:bg-gray-100 focus:ring-1 focus:ring-[#2E2F7C] focus:outline-none focus-visible:outline-0 disabled:bg-gray-100"
|
||||||
/>
|
/>
|
||||||
<div className="">
|
|
||||||
<HexColorInput
|
|
||||||
color={rgbColor}
|
|
||||||
onChange={handleChangeColor}
|
|
||||||
prefixed
|
|
||||||
className="relative z-10 mt-1 flex w-full rounded-lg border px-3 py-2 text-sm focus:ring-0 focus-visible:outline-0"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
</div>
|
||||||
</div>
|
)}
|
||||||
<EditorButton
|
|
||||||
onClick={() => editor.chain().focus().setTextAlign('left').run()}
|
|
||||||
disabled={
|
|
||||||
disabled ||
|
|
||||||
!editor.can().chain().focus().setTextAlign('left').run()
|
|
||||||
}
|
|
||||||
isActive={editor.isActive({ textAlign: 'left' })}
|
|
||||||
title="Align Left"
|
|
||||||
>
|
|
||||||
<Bars3BottomLeftIcon />
|
|
||||||
</EditorButton>
|
|
||||||
<EditorButton
|
|
||||||
onClick={() =>
|
|
||||||
editor.chain().focus().setTextAlign('center').run()
|
|
||||||
}
|
|
||||||
disabled={
|
|
||||||
disabled ||
|
|
||||||
!editor.can().chain().focus().setTextAlign('center').run()
|
|
||||||
}
|
|
||||||
isActive={editor.isActive({ textAlign: 'center' })}
|
|
||||||
title="Align Center"
|
|
||||||
>
|
|
||||||
<Bars3Icon />
|
|
||||||
</EditorButton>
|
|
||||||
<EditorButton
|
|
||||||
onClick={() => editor.chain().focus().setTextAlign('right').run()}
|
|
||||||
disabled={
|
|
||||||
disabled ||
|
|
||||||
!editor.can().chain().focus().setTextAlign('right').run()
|
|
||||||
}
|
|
||||||
isActive={editor.isActive({ textAlign: 'right' })}
|
|
||||||
title="Align Right"
|
|
||||||
>
|
|
||||||
<Bars3BottomRightIcon />
|
|
||||||
</EditorButton>
|
|
||||||
<EditorButton
|
|
||||||
onClick={() =>
|
|
||||||
editor.chain().focus().setTextAlign('justify').run()
|
|
||||||
}
|
|
||||||
disabled={
|
|
||||||
disabled ||
|
|
||||||
!editor.can().chain().focus().setTextAlign('justify').run()
|
|
||||||
}
|
|
||||||
isActive={editor.isActive({ textAlign: 'justify' })}
|
|
||||||
title="Align Justify"
|
|
||||||
>
|
|
||||||
<Bars4Icon />
|
|
||||||
</EditorButton>
|
|
||||||
</div>
|
</div>
|
||||||
<div className="flex max-w-[150px] flex-wrap items-start gap-1 px-1">
|
<EditorButton
|
||||||
<EditorButton
|
onClick={() => editor.chain().focus().setTextAlign('left').run()}
|
||||||
onClick={() =>
|
disabled={
|
||||||
editor.chain().focus().toggleHeading({ level: 1 }).run()
|
disabled ||
|
||||||
}
|
!editor.can().chain().focus().setTextAlign('left').run()
|
||||||
isActive={editor.isActive('heading', { level: 1 })}
|
}
|
||||||
title="Heading 1"
|
isActive={editor.isActive({ textAlign: 'left' })}
|
||||||
disabled={disabled}
|
title="Align Left"
|
||||||
>
|
>
|
||||||
<H1Icon />
|
<Bars3BottomLeftIcon />
|
||||||
</EditorButton>
|
</EditorButton>
|
||||||
<EditorButton
|
<EditorButton
|
||||||
onClick={() =>
|
onClick={() => editor.chain().focus().setTextAlign('center').run()}
|
||||||
editor.chain().focus().toggleHeading({ level: 2 }).run()
|
disabled={
|
||||||
}
|
disabled ||
|
||||||
isActive={editor.isActive('heading', { level: 2 })}
|
!editor.can().chain().focus().setTextAlign('center').run()
|
||||||
title="Heading 2"
|
}
|
||||||
disabled={disabled}
|
isActive={editor.isActive({ textAlign: 'center' })}
|
||||||
>
|
title="Align Center"
|
||||||
<H2Icon />
|
>
|
||||||
</EditorButton>
|
<Bars3Icon />
|
||||||
<EditorButton
|
</EditorButton>
|
||||||
onClick={() =>
|
<EditorButton
|
||||||
editor.chain().focus().toggleHeading({ level: 3 }).run()
|
onClick={() => editor.chain().focus().setTextAlign('right').run()}
|
||||||
}
|
disabled={
|
||||||
isActive={editor.isActive('heading', { level: 3 })}
|
disabled ||
|
||||||
title="Heading 3"
|
!editor.can().chain().focus().setTextAlign('right').run()
|
||||||
disabled={disabled}
|
}
|
||||||
>
|
isActive={editor.isActive({ textAlign: 'right' })}
|
||||||
<H3Icon />
|
title="Align Right"
|
||||||
</EditorButton>
|
>
|
||||||
{/* <EditorButton
|
<Bars3BottomRightIcon />
|
||||||
|
</EditorButton>
|
||||||
|
<EditorButton
|
||||||
|
onClick={() => editor.chain().focus().setTextAlign('justify').run()}
|
||||||
|
disabled={
|
||||||
|
disabled ||
|
||||||
|
!editor.can().chain().focus().setTextAlign('justify').run()
|
||||||
|
}
|
||||||
|
isActive={editor.isActive({ textAlign: 'justify' })}
|
||||||
|
title="Align Justify"
|
||||||
|
>
|
||||||
|
<Bars4Icon />
|
||||||
|
</EditorButton>
|
||||||
|
</div>
|
||||||
|
<div className="flex max-w-[150px] flex-wrap items-start gap-1 px-1">
|
||||||
|
<EditorButton
|
||||||
|
onClick={() =>
|
||||||
|
editor.chain().focus().toggleHeading({ level: 1 }).run()
|
||||||
|
}
|
||||||
|
isActive={editor.isActive('heading', { level: 1 })}
|
||||||
|
title="Heading 1"
|
||||||
|
disabled={disabled}
|
||||||
|
>
|
||||||
|
<H1Icon />
|
||||||
|
</EditorButton>
|
||||||
|
<EditorButton
|
||||||
|
onClick={() =>
|
||||||
|
editor.chain().focus().toggleHeading({ level: 2 }).run()
|
||||||
|
}
|
||||||
|
isActive={editor.isActive('heading', { level: 2 })}
|
||||||
|
title="Heading 2"
|
||||||
|
disabled={disabled}
|
||||||
|
>
|
||||||
|
<H2Icon />
|
||||||
|
</EditorButton>
|
||||||
|
<EditorButton
|
||||||
|
onClick={() =>
|
||||||
|
editor.chain().focus().toggleHeading({ level: 3 }).run()
|
||||||
|
}
|
||||||
|
isActive={editor.isActive('heading', { level: 3 })}
|
||||||
|
title="Heading 3"
|
||||||
|
disabled={disabled}
|
||||||
|
>
|
||||||
|
<H3Icon />
|
||||||
|
</EditorButton>
|
||||||
|
{/* <EditorButton
|
||||||
onClick={() => editor.chain().focus().setParagraph().run()}
|
onClick={() => editor.chain().focus().setParagraph().run()}
|
||||||
isActive={editor.isActive('paragraph')}
|
isActive={editor.isActive('paragraph')}
|
||||||
title="Paragraph"
|
title="Paragraph"
|
||||||
@ -264,32 +266,32 @@ export const EditorMenuBar = (properties: TProperties) => {
|
|||||||
>
|
>
|
||||||
<RiParagraph />
|
<RiParagraph />
|
||||||
</EditorButton> */}
|
</EditorButton> */}
|
||||||
<EditorButton
|
<EditorButton
|
||||||
onClick={() => editor.chain().focus().toggleBulletList().run()}
|
onClick={() => editor.chain().focus().toggleBulletList().run()}
|
||||||
isActive={editor.isActive('bulletList')}
|
isActive={editor.isActive('bulletList')}
|
||||||
title="Bullet List"
|
title="Bullet List"
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
>
|
>
|
||||||
<ListBulletIcon />
|
<ListBulletIcon />
|
||||||
</EditorButton>
|
</EditorButton>
|
||||||
<EditorButton
|
<EditorButton
|
||||||
onClick={() => editor.chain().focus().toggleOrderedList().run()}
|
onClick={() => editor.chain().focus().toggleOrderedList().run()}
|
||||||
isActive={editor.isActive('orderedList')}
|
isActive={editor.isActive('orderedList')}
|
||||||
title="Ordered List"
|
title="Ordered List"
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
>
|
>
|
||||||
<NumberedListIcon />
|
<NumberedListIcon />
|
||||||
</EditorButton>
|
</EditorButton>
|
||||||
<EditorButton
|
<EditorButton
|
||||||
onClick={() => editor.chain().focus().toggleCodeBlock().run()}
|
onClick={() => editor.chain().focus().toggleCodeBlock().run()}
|
||||||
isActive={editor.isActive('codeBlock')}
|
isActive={editor.isActive('codeBlock')}
|
||||||
title="Code Block"
|
title="Code Block"
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
>
|
>
|
||||||
<CodeBracketIcon />
|
<CodeBracketIcon />
|
||||||
</EditorButton>
|
</EditorButton>
|
||||||
</div>
|
</div>
|
||||||
{/* <div className="flex items-start gap-1 px-1">
|
{/* <div className="flex items-start gap-1 px-1">
|
||||||
<EditorButton
|
<EditorButton
|
||||||
onClick={() => editor.chain().focus().toggleBlockquote().run()}
|
onClick={() => editor.chain().focus().toggleBlockquote().run()}
|
||||||
isActive={editor.isActive('blockquote')}
|
isActive={editor.isActive('blockquote')}
|
||||||
@ -306,7 +308,7 @@ export const EditorMenuBar = (properties: TProperties) => {
|
|||||||
<RiSeparator />
|
<RiSeparator />
|
||||||
</EditorButton>
|
</EditorButton>
|
||||||
</div> */}
|
</div> */}
|
||||||
{/* <div className="flex items-start gap-1 px-1">
|
{/* <div className="flex items-start gap-1 px-1">
|
||||||
<EditorButton
|
<EditorButton
|
||||||
onClick={() => editor.chain().focus().setHardBreak().run()}
|
onClick={() => editor.chain().focus().setHardBreak().run()}
|
||||||
title="Hard Break"
|
title="Hard Break"
|
||||||
@ -325,89 +327,96 @@ export const EditorMenuBar = (properties: TProperties) => {
|
|||||||
<RiFormatClear />
|
<RiFormatClear />
|
||||||
</EditorButton>
|
</EditorButton>
|
||||||
</div> */}
|
</div> */}
|
||||||
<div className="flex items-start gap-1 px-1">
|
<div className="flex items-start gap-1 px-1">
|
||||||
|
<div className="relative">
|
||||||
<EditorButton
|
<EditorButton
|
||||||
onClick={() => toggleUpload()}
|
onClick={() => setIsOpenImage(true)}
|
||||||
title="Insert Image"
|
title="Insert Image"
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
>
|
>
|
||||||
<PhotoIcon />
|
<PhotoIcon />
|
||||||
</EditorButton>
|
</EditorButton>
|
||||||
<EditorButton
|
{isOpenImage && (
|
||||||
onClick={() => setLink()}
|
<div
|
||||||
disabled={
|
className="border-md absolute top-8 left-0 w-50"
|
||||||
disabled ||
|
ref={popover}
|
||||||
!editor
|
>
|
||||||
.can()
|
<div className="relative">
|
||||||
.chain()
|
<Input
|
||||||
.focus()
|
placeholder="Masukkan URL Gambar"
|
||||||
.extendMarkRange('link')
|
color={rgbColor}
|
||||||
.setLink({ href: '' })
|
onChange={(event) => {
|
||||||
.run()
|
setImageUrl(event.target.value)
|
||||||
}
|
}}
|
||||||
isActive={editor.isActive('link')}
|
className="z-10 flex h-[42px] w-full rounded-lg border-0 bg-white p-2 pr-8 text-sm shadow read-only:bg-gray-100 focus:ring-1 focus:ring-[#2E2F7C] focus:outline-none focus-visible:outline-0 disabled:bg-gray-100"
|
||||||
title="Set Link"
|
/>
|
||||||
>
|
<Button
|
||||||
<LinkIcon />
|
type="button"
|
||||||
</EditorButton>
|
variant="icon"
|
||||||
<EditorButton
|
size="fit"
|
||||||
onClick={() => editor.chain().focus().unsetLink().run()}
|
className="absolute top-0 right-3 h-[42px]"
|
||||||
disabled={disabled || !editor.isActive('link')}
|
onClick={() => {
|
||||||
title="Unset Link"
|
setIsUploadOpen('content')
|
||||||
>
|
}}
|
||||||
<LinkSlashIcon />
|
>
|
||||||
</EditorButton>
|
<CloudArrowUpIcon className="h-4 w-4 text-gray-500/50" />
|
||||||
</div>
|
</Button>
|
||||||
<div className="flex items-start gap-1 px-1">
|
</div>
|
||||||
<EditorButton
|
</div>
|
||||||
onClick={() => editor.chain().focus().undo().run()}
|
)}
|
||||||
disabled={disabled || !editor.can().chain().focus().undo().run()}
|
|
||||||
title="Undo"
|
|
||||||
>
|
|
||||||
<ArrowUturnLeftIcon />
|
|
||||||
</EditorButton>
|
|
||||||
<EditorButton
|
|
||||||
onClick={() => editor.chain().focus().redo().run()}
|
|
||||||
disabled={disabled || !editor.can().chain().focus().redo().run()}
|
|
||||||
title="Redo"
|
|
||||||
>
|
|
||||||
<ArrowUturnRightIcon />
|
|
||||||
</EditorButton>
|
|
||||||
</div>
|
</div>
|
||||||
|
<EditorButton
|
||||||
|
onClick={() => setLink()}
|
||||||
|
disabled={
|
||||||
|
disabled ||
|
||||||
|
!editor
|
||||||
|
.can()
|
||||||
|
.chain()
|
||||||
|
.focus()
|
||||||
|
.extendMarkRange('link')
|
||||||
|
.setLink({ href: '' })
|
||||||
|
.run()
|
||||||
|
}
|
||||||
|
isActive={editor.isActive('link')}
|
||||||
|
title="Set Link"
|
||||||
|
>
|
||||||
|
<LinkIcon />
|
||||||
|
</EditorButton>
|
||||||
|
<EditorButton
|
||||||
|
onClick={() => editor.chain().focus().unsetLink().run()}
|
||||||
|
disabled={disabled || !editor.isActive('link')}
|
||||||
|
title="Unset Link"
|
||||||
|
>
|
||||||
|
<LinkSlashIcon />
|
||||||
|
</EditorButton>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div className="flex items-start gap-1 px-1">
|
||||||
<div className="flex gap-1 px-1">
|
<EditorButton
|
||||||
<EditorButton
|
onClick={() => editor.chain().focus().undo().run()}
|
||||||
onClick={() => setIsPlainHTML(true)}
|
disabled={disabled || !editor.can().chain().focus().undo().run()}
|
||||||
title="Switch to Plain Text"
|
title="Undo"
|
||||||
>
|
>
|
||||||
<DocumentTextIcon />
|
<ArrowUturnLeftIcon />
|
||||||
</EditorButton>
|
</EditorButton>
|
||||||
</div>
|
<EditorButton
|
||||||
|
onClick={() => editor.chain().focus().redo().run()}
|
||||||
|
disabled={disabled || !editor.can().chain().focus().redo().run()}
|
||||||
|
title="Redo"
|
||||||
|
>
|
||||||
|
<ArrowUturnRightIcon />
|
||||||
|
</EditorButton>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
{/* <Dialog
|
<div className="flex gap-1 px-1">
|
||||||
isOpen={isOpenImage}
|
<EditorButton
|
||||||
setIsOpen={setIsOpenImage}
|
onClick={() => setIsPlainHTML(true)}
|
||||||
title="Insert Image"
|
title="Switch to Plain Text"
|
||||||
showCloseButton={true}
|
>
|
||||||
>
|
<DocumentTextIcon />
|
||||||
<UploadProvider
|
</EditorButton>
|
||||||
data={{
|
</div>
|
||||||
onCancel: () => setIsOpenImage(false),
|
</div>
|
||||||
onSave: (file) => {
|
</div>
|
||||||
addImage(file)
|
|
||||||
setIsOpenImage(false)
|
|
||||||
},
|
|
||||||
category: category,
|
|
||||||
maxFileSize: 300,
|
|
||||||
selectedFile: '',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Upload />
|
|
||||||
</UploadProvider>
|
|
||||||
</Dialog> */}
|
|
||||||
</>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,7 +11,7 @@ import {
|
|||||||
import { useRemixFormContext } from 'remix-hook-form'
|
import { useRemixFormContext } from 'remix-hook-form'
|
||||||
import { twMerge } from 'tailwind-merge'
|
import { twMerge } from 'tailwind-merge'
|
||||||
|
|
||||||
import { useAdminContext } from '~/contexts/admin'
|
import { useAdminContext, type TUpload } from '~/contexts/admin'
|
||||||
|
|
||||||
import { Button } from './button'
|
import { Button } from './button'
|
||||||
|
|
||||||
@ -42,7 +42,8 @@ export const InputFile = <TFormValues extends Record<string, unknown>>(
|
|||||||
labelClassName,
|
labelClassName,
|
||||||
...restProperties
|
...restProperties
|
||||||
} = properties
|
} = properties
|
||||||
const { setIsUploadOpen, uploadedFile, setUploadedFile } = useAdminContext()
|
const { setIsUploadOpen, uploadedFile, setUploadedFile, isUploadOpen } =
|
||||||
|
useAdminContext()
|
||||||
|
|
||||||
const {
|
const {
|
||||||
register,
|
register,
|
||||||
@ -53,9 +54,10 @@ export const InputFile = <TFormValues extends Record<string, unknown>>(
|
|||||||
const error: FieldError = get(errors, name)
|
const error: FieldError = get(errors, name)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (uploadedFile) {
|
if (uploadedFile && isUploadOpen === name) {
|
||||||
setValue(name as string, uploadedFile)
|
setValue(name as string, uploadedFile)
|
||||||
setUploadedFile(undefined)
|
setUploadedFile(undefined)
|
||||||
|
setIsUploadOpen(undefined)
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [uploadedFile])
|
}, [uploadedFile])
|
||||||
@ -84,7 +86,7 @@ export const InputFile = <TFormValues extends Record<string, unknown>>(
|
|||||||
size="fit"
|
size="fit"
|
||||||
className="absolute right-3 h-[42px]"
|
className="absolute right-3 h-[42px]"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setIsUploadOpen('featured_image')
|
setIsUploadOpen(name as TUpload)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<CloudArrowUpIcon className="h-4 w-4 text-gray-500/50" />
|
<CloudArrowUpIcon className="h-4 w-4 text-gray-500/50" />
|
||||||
|
|||||||
@ -12,7 +12,7 @@ export const uploadCategorySchema = z
|
|||||||
.enum(['featured_image', 'ads', 'content', 'profile_picture'])
|
.enum(['featured_image', 'ads', 'content', 'profile_picture'])
|
||||||
.optional()
|
.optional()
|
||||||
|
|
||||||
type TUpload = z.infer<typeof uploadCategorySchema>
|
export type TUpload = z.infer<typeof uploadCategorySchema>
|
||||||
|
|
||||||
type AdminContextProperties = {
|
type AdminContextProperties = {
|
||||||
isUploadOpen: TUpload
|
isUploadOpen: TUpload
|
||||||
|
|||||||
@ -15,11 +15,11 @@ export const uploadSchema = z.object({
|
|||||||
export type TUploadSchema = z.infer<typeof uploadSchema>
|
export type TUploadSchema = z.infer<typeof uploadSchema>
|
||||||
|
|
||||||
export const FormUpload = () => {
|
export const FormUpload = () => {
|
||||||
const { isUploadOpen, setUploadedFile, setIsUploadOpen } = useAdminContext()
|
const { isUploadOpen, setUploadedFile } = useAdminContext()
|
||||||
const fetcher = useFetcher()
|
const fetcher = useFetcher()
|
||||||
const [disabled, setDisabled] = useState(false)
|
const [disabled, setDisabled] = useState(false)
|
||||||
const [error, setError] = useState<string>()
|
const [error, setError] = useState<string>()
|
||||||
const maxFileSize = 1024 // 1MB
|
const maxFileSize = 10 * 1024 // 10MB
|
||||||
|
|
||||||
const formMethods = useRemixForm<TUploadSchema>({
|
const formMethods = useRemixForm<TUploadSchema>({
|
||||||
mode: 'onSubmit',
|
mode: 'onSubmit',
|
||||||
@ -37,7 +37,6 @@ export const FormUpload = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setUploadedFile(fetcher.data.uploadData.data.file_url)
|
setUploadedFile(fetcher.data.uploadData.data.file_url)
|
||||||
setIsUploadOpen(undefined)
|
|
||||||
|
|
||||||
setDisabled(true)
|
setDisabled(true)
|
||||||
setError(undefined)
|
setError(undefined)
|
||||||
|
|||||||
@ -1,4 +1,8 @@
|
|||||||
import { ClipboardDocumentCheckIcon, TagIcon } from '@heroicons/react/20/solid'
|
import {
|
||||||
|
ClipboardDocumentCheckIcon,
|
||||||
|
DocumentCurrencyDollarIcon,
|
||||||
|
TagIcon,
|
||||||
|
} from '@heroicons/react/20/solid'
|
||||||
import type { SVGProps } from 'react'
|
import type { SVGProps } from 'react'
|
||||||
|
|
||||||
import { ChartIcon } from '~/components/icons/chart'
|
import { ChartIcon } from '~/components/icons/chart'
|
||||||
@ -62,7 +66,7 @@ export const MENU: TMenu[] = [
|
|||||||
{
|
{
|
||||||
title: 'Subscribe Plan',
|
title: 'Subscribe Plan',
|
||||||
url: '/lg-admin/subscribe-plan',
|
url: '/lg-admin/subscribe-plan',
|
||||||
icon: TagIcon,
|
icon: DocumentCurrencyDollarIcon,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|||||||
@ -83,7 +83,7 @@ export const ContentsPage = () => {
|
|||||||
7: (value: string) => (
|
7: (value: string) => (
|
||||||
<Button
|
<Button
|
||||||
as="a"
|
as="a"
|
||||||
href={`/lg-admin/contents/update/${value}`}
|
href={`/lg-admin/contents/update/${encodeURIComponent(value)}`}
|
||||||
className="text-md rounded-md"
|
className="text-md rounded-md"
|
||||||
size="sm"
|
size="sm"
|
||||||
>
|
>
|
||||||
|
|||||||
@ -24,6 +24,6 @@ export const getPremiumAttribute = (parameters: TGetPremiumAttribute) => {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
as: Link,
|
as: Link,
|
||||||
to: `/detail/${slug}`,
|
to: `/detail/${encodeURIComponent(slug)}`,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user