announcement
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { FC, useEffect, useRef, useState } from 'react'
|
import { FC, useEffect, useRef } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import Button from '../../components/Button'
|
import Button from '../../components/Button'
|
||||||
import { InfoCircle, TickCircle } from 'iconsax-react'
|
import { InfoCircle, TickCircle } from 'iconsax-react'
|
||||||
@@ -6,29 +6,22 @@ import Input from '../../components/Input'
|
|||||||
import Quill from 'quill'
|
import Quill from 'quill'
|
||||||
import DatePickerComponent from '../../components/DatePicker'
|
import DatePickerComponent from '../../components/DatePicker'
|
||||||
import CheckBoxComponent from '../../components/CheckBoxComponent'
|
import CheckBoxComponent from '../../components/CheckBoxComponent'
|
||||||
import Select from '../../components/Select'
|
|
||||||
import { useGetAllServices } from '../service/hooks/useServiceData'
|
|
||||||
import { useFormik } from 'formik'
|
import { useFormik } from 'formik'
|
||||||
import { AnnoncementCreateType, UserServiceItemType } from './types/AnnoncementTypes'
|
import { AnnoncementCreateType } from './types/AnnoncementTypes'
|
||||||
import * as Yup from 'yup'
|
import * as Yup from 'yup'
|
||||||
import { ServiceItemType } from '../service/types/ServiceTypes'
|
|
||||||
import { useCreateAnnoncement, useGetCustomersService } from './hooks/useAnnoncementData'
|
|
||||||
import { ErrorType } from '../../helpers/types'
|
import { ErrorType } from '../../helpers/types'
|
||||||
import { toast } from 'react-toastify'
|
import { toast } from 'react-toastify'
|
||||||
import moment from 'moment-jalaali'
|
import moment from 'moment-jalaali'
|
||||||
import { useNavigate } from 'react-router-dom'
|
import { useNavigate } from 'react-router-dom'
|
||||||
import { Pages } from '../../config/Pages'
|
import { Pages } from '../../config/Pages'
|
||||||
|
import { useCreateAnnoncement } from './hooks/useAnnoncementData'
|
||||||
|
|
||||||
const Create: FC = () => {
|
const Create: FC = () => {
|
||||||
|
|
||||||
const { t } = useTranslation('global')
|
const { t } = useTranslation('global')
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const editorRef = useRef<HTMLDivElement | null>(null);
|
const editorRef = useRef<HTMLDivElement | null>(null);
|
||||||
const [serviceId, setServiceId] = useState('')
|
const createAnnoncement = useCreateAnnoncement();
|
||||||
const [customerId, setCustomerId] = useState<string>('')
|
|
||||||
const getServices = useGetAllServices('', 1, '', '', false)
|
|
||||||
const createAnnoncement = useCreateAnnoncement()
|
|
||||||
const getCustomer = useGetCustomersService(serviceId)
|
|
||||||
|
|
||||||
const formik = useFormik<AnnoncementCreateType>({
|
const formik = useFormik<AnnoncementCreateType>({
|
||||||
initialValues: {
|
initialValues: {
|
||||||
@@ -37,9 +30,6 @@ const Create: FC = () => {
|
|||||||
publishAt: '',
|
publishAt: '',
|
||||||
isPublic: false,
|
isPublic: false,
|
||||||
isImportant: false,
|
isImportant: false,
|
||||||
serviceId: '',
|
|
||||||
groupIds: [],
|
|
||||||
userIds: undefined
|
|
||||||
},
|
},
|
||||||
validationSchema: Yup.object({
|
validationSchema: Yup.object({
|
||||||
title: Yup.string().required(t('errors.required')),
|
title: Yup.string().required(t('errors.required')),
|
||||||
@@ -47,13 +37,6 @@ const Create: FC = () => {
|
|||||||
publishAt: Yup.string().required(t('errors.required')),
|
publishAt: Yup.string().required(t('errors.required')),
|
||||||
}),
|
}),
|
||||||
onSubmit: (values) => {
|
onSubmit: (values) => {
|
||||||
if (!values.serviceId) {
|
|
||||||
values.serviceId = undefined
|
|
||||||
}
|
|
||||||
if (customerId) {
|
|
||||||
values.serviceId = undefined
|
|
||||||
values.userIds = [customerId]
|
|
||||||
}
|
|
||||||
createAnnoncement.mutate(values, {
|
createAnnoncement.mutate(values, {
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
formik.resetForm()
|
formik.resetForm()
|
||||||
@@ -157,32 +140,6 @@ const Create: FC = () => {
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className='mt-5'>
|
|
||||||
<Select
|
|
||||||
label={t('announcement.contact_announcement')}
|
|
||||||
placeholder={t('announcement.select_service')}
|
|
||||||
items={getServices?.data?.data?.services?.map((item: ServiceItemType) => ({
|
|
||||||
label: item.name,
|
|
||||||
value: item.id
|
|
||||||
})) || []}
|
|
||||||
name='serviceId'
|
|
||||||
onChange={(e) => {
|
|
||||||
formik.setFieldValue('serviceId', e.target.value)
|
|
||||||
setServiceId(e.target.value)
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div className='mt-5'>
|
|
||||||
<Select
|
|
||||||
placeholder={t('select')}
|
|
||||||
label={t('announcement.select_customer')}
|
|
||||||
items={getCustomer?.data?.data?.users?.map((item: UserServiceItemType) => ({
|
|
||||||
label: item.firstname + ' ' + item.lastname,
|
|
||||||
value: item.id
|
|
||||||
})) || []}
|
|
||||||
onChange={(e) => setCustomerId(e.target.value)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { FC, useEffect, useRef, useState } from 'react'
|
import { FC, useEffect, useRef } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import Button from '../../components/Button'
|
import Button from '../../components/Button'
|
||||||
import { InfoCircle, TickCircle } from 'iconsax-react'
|
import { InfoCircle, TickCircle } from 'iconsax-react'
|
||||||
@@ -6,13 +6,10 @@ import Input from '../../components/Input'
|
|||||||
import Quill from 'quill'
|
import Quill from 'quill'
|
||||||
import DatePickerComponent from '../../components/DatePicker'
|
import DatePickerComponent from '../../components/DatePicker'
|
||||||
import CheckBoxComponent from '../../components/CheckBoxComponent'
|
import CheckBoxComponent from '../../components/CheckBoxComponent'
|
||||||
import Select from '../../components/Select'
|
|
||||||
import { useGetAllServices } from '../service/hooks/useServiceData'
|
|
||||||
import { useFormik } from 'formik'
|
import { useFormik } from 'formik'
|
||||||
import { AnnoncementCreateType, UserServiceItemType } from './types/AnnoncementTypes'
|
import { AnnoncementCreateType } from './types/AnnoncementTypes'
|
||||||
import * as Yup from 'yup'
|
import * as Yup from 'yup'
|
||||||
import { ServiceItemType } from '../service/types/ServiceTypes'
|
import { useGetAnnoncementDetail, useUpdateAnnoncement } from './hooks/useAnnoncementData'
|
||||||
import { useGetAnnoncementDetail, useGetCustomersService, useUpdateAnnoncement } from './hooks/useAnnoncementData'
|
|
||||||
import { ErrorType } from '../../helpers/types'
|
import { ErrorType } from '../../helpers/types'
|
||||||
import { toast } from 'react-toastify'
|
import { toast } from 'react-toastify'
|
||||||
import moment from 'moment-jalaali'
|
import moment from 'moment-jalaali'
|
||||||
@@ -25,10 +22,6 @@ const Update: FC = () => {
|
|||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const { id } = useParams()
|
const { id } = useParams()
|
||||||
const editorRef = useRef<HTMLDivElement | null>(null);
|
const editorRef = useRef<HTMLDivElement | null>(null);
|
||||||
const [serviceId, setServiceId] = useState('')
|
|
||||||
const [customerId, setCustomerId] = useState<string>('')
|
|
||||||
const getServices = useGetAllServices('', 1, '', '', false)
|
|
||||||
const getCustomer = useGetCustomersService(serviceId)
|
|
||||||
const getAnnoncement = useGetAnnoncementDetail(id || '')
|
const getAnnoncement = useGetAnnoncementDetail(id || '')
|
||||||
const updateAnnoncement = useUpdateAnnoncement(id || '')
|
const updateAnnoncement = useUpdateAnnoncement(id || '')
|
||||||
|
|
||||||
@@ -39,9 +32,6 @@ const Update: FC = () => {
|
|||||||
publishAt: '',
|
publishAt: '',
|
||||||
isPublic: false,
|
isPublic: false,
|
||||||
isImportant: false,
|
isImportant: false,
|
||||||
serviceId: '',
|
|
||||||
groupIds: [],
|
|
||||||
userIds: undefined
|
|
||||||
},
|
},
|
||||||
validationSchema: Yup.object({
|
validationSchema: Yup.object({
|
||||||
title: Yup.string().required(t('errors.required')),
|
title: Yup.string().required(t('errors.required')),
|
||||||
@@ -49,13 +39,6 @@ const Update: FC = () => {
|
|||||||
publishAt: Yup.string().required(t('errors.required')),
|
publishAt: Yup.string().required(t('errors.required')),
|
||||||
}),
|
}),
|
||||||
onSubmit: (values) => {
|
onSubmit: (values) => {
|
||||||
if (!values.serviceId) {
|
|
||||||
values.serviceId = undefined
|
|
||||||
}
|
|
||||||
if (customerId) {
|
|
||||||
values.serviceId = undefined
|
|
||||||
values.userIds = [customerId]
|
|
||||||
}
|
|
||||||
updateAnnoncement.mutate(values, {
|
updateAnnoncement.mutate(values, {
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
formik.resetForm()
|
formik.resetForm()
|
||||||
@@ -95,8 +78,6 @@ const Update: FC = () => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (getAnnoncement.data) {
|
if (getAnnoncement.data) {
|
||||||
formik.setValues(getAnnoncement.data?.data?.announcement)
|
formik.setValues(getAnnoncement.data?.data?.announcement)
|
||||||
setServiceId(getAnnoncement.data?.data?.announcement?.targetService?.id)
|
|
||||||
setCustomerId(getAnnoncement.data?.data?.announcement?.userIds?.[0])
|
|
||||||
|
|
||||||
const editorElement = editorRef.current?.querySelector('.ql-editor');
|
const editorElement = editorRef.current?.querySelector('.ql-editor');
|
||||||
if (editorElement) {
|
if (editorElement) {
|
||||||
@@ -177,32 +158,6 @@ const Update: FC = () => {
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className='mt-5'>
|
|
||||||
<Select
|
|
||||||
label={t('announcement.contact_announcement')}
|
|
||||||
placeholder={t('announcement.select_service')}
|
|
||||||
items={getServices?.data?.data?.services?.map((item: ServiceItemType) => ({
|
|
||||||
label: item.name,
|
|
||||||
value: item.id
|
|
||||||
})) || []}
|
|
||||||
name='serviceId'
|
|
||||||
onChange={(e) => {
|
|
||||||
formik.setFieldValue('serviceId', e.target.value)
|
|
||||||
setServiceId(e.target.value)
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div className='mt-5'>
|
|
||||||
<Select
|
|
||||||
placeholder={t('select')}
|
|
||||||
label={t('announcement.select_customer')}
|
|
||||||
items={getCustomer?.data?.data?.users?.map((item: UserServiceItemType) => ({
|
|
||||||
label: item.firstname + ' ' + item.lastname,
|
|
||||||
value: item.id
|
|
||||||
})) || []}
|
|
||||||
onChange={(e) => setCustomerId(e.target.value)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -4,9 +4,6 @@ export type AnnoncementCreateType = {
|
|||||||
publishAt: string;
|
publishAt: string;
|
||||||
isPublic: boolean;
|
isPublic: boolean;
|
||||||
isImportant: boolean;
|
isImportant: boolean;
|
||||||
serviceId?: string;
|
|
||||||
groupIds: string[];
|
|
||||||
userIds?: string[];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type AnnoncementItemType = {
|
export type AnnoncementItemType = {
|
||||||
|
|||||||
@@ -4,6 +4,4 @@ export type CreateAnnouncementType = {
|
|||||||
publishAt: string;
|
publishAt: string;
|
||||||
isPublic: boolean;
|
isPublic: boolean;
|
||||||
isImportant: boolean;
|
isImportant: boolean;
|
||||||
serviceId?: string;
|
|
||||||
groupIds: string[];
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user