admin ticket

This commit is contained in:
hamid zarghami
2025-02-01 16:41:30 +03:30
parent 4947ae8749
commit 7bafdf57ad
9 changed files with 504 additions and 182 deletions
+7
View File
@@ -1,7 +1,9 @@
import { FC, InputHTMLAttributes } from 'react'
import Error from './Error'
type Props = {
label: string,
error_text?: string
} & InputHTMLAttributes<HTMLTextAreaElement>
const Textarea: FC<Props> = (props: Props) => {
@@ -18,6 +20,11 @@ const Textarea: FC<Props> = (props: Props) => {
</textarea>
{
props.error_text &&
<Error errorText={props.error_text} />
}
</div>
)
}
+56 -9
View File
@@ -1,22 +1,57 @@
import { FC, useCallback, useState } from 'react'
import { FC, useCallback, useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { useDropzone } from 'react-dropzone'
import { CloseCircle } from 'iconsax-react'
type Props = {
label: string,
isMultiple?: boolean,
onChange?: (file: File[]) => void;
isReset?: boolean;
}
const UploadBox: FC<Props> = (props: Props) => {
const { t } = useTranslation('global')
const [file, setFile] = useState<File>()
const [files, setFiles] = useState<File[]>([])
const onDrop = useCallback((acceptedFiles: File[]) => {
setFile(acceptedFiles[0])
}, [])
if (props.isMultiple) {
const array = [...files]
array.push(acceptedFiles[0])
setFiles(array)
if (props.onChange) {
props.onChange(array);
}
} else {
setFiles([acceptedFiles[0]])
if (props.onChange) {
props.onChange([acceptedFiles[0]])
}
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [files])
const { getRootProps, getInputProps } = useDropzone({ onDrop })
const handleRemove = (index: number) => {
const array = [...files]
array.splice(index, 1)
setFiles(array)
if (props.onChange) {
props.onChange(array)
}
}
useEffect(() => {
if (props.isReset) {
setFiles([])
}
}, [props.isReset])
return (
<div>
@@ -28,15 +63,27 @@ const UploadBox: FC<Props> = (props: Props) => {
{t('select_file')}
</button>
<div className='text-description text-xs'>
<div className='lg:flex gap-2 hidden'>
{
file ?
file.name
:
t('no_select_file')
files?.map((item, index) => (
<div key={index} className='flex bg-gray-200 py-1.5 px-2 rounded-lg items-center gap-1'>
<CloseCircle onClick={() => handleRemove(index)} size={16} color='red' />
<div className='text-xs'>{item.name}</div>
</div>
))
}
</div>
</div>
<div className='lg:hidden gap-2 flex flex-wrap mt-4'>
{
files?.map((item, index) => (
<div key={index} className='flex bg-gray-200 py-1.5 px-2 rounded-lg items-center gap-1'>
<CloseCircle onClick={() => handleRemove(index)} size={16} color='red' />
<div className='text-xs'>{item.name}</div>
</div>
))
}
</div>
</div>
)
}