annoncement
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
VITE_TOKEN_NAME = 'admin_token'
|
||||
VITE_REFRESH_TOKEN_NAME = 'admin_refresh_token'
|
||||
# VITE_BASE_URL = 'https://api.danakcorp.com'
|
||||
VITE_BASE_URL = 'http://192.168.0.216:4000'
|
||||
VITE_BASE_URL = 'https://api.danakcorp.com'
|
||||
# VITE_BASE_URL = 'http://192.168.0.216:4000'
|
||||
+2
-1
@@ -470,7 +470,8 @@
|
||||
"date_created": "تاریخ ثبت",
|
||||
"summary": "خلاصه اطلاعیه",
|
||||
"user": "کاربر مخاطب",
|
||||
"created_date": "زمان ایجاد"
|
||||
"created_date": "زمان ایجاد",
|
||||
"service": "سرویس"
|
||||
},
|
||||
"back": "بازگشت",
|
||||
"criticisms": {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { FC, useEffect, useRef } from 'react'
|
||||
import { FC, useEffect, useRef, useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import Button from '../../components/Button'
|
||||
import { InfoCircle, TickCircle } from 'iconsax-react'
|
||||
@@ -9,20 +9,26 @@ import CheckBoxComponent from '../../components/CheckBoxComponent'
|
||||
import Select from '../../components/Select'
|
||||
import { useGetAllServices } from '../service/hooks/useServiceData'
|
||||
import { useFormik } from 'formik'
|
||||
import { AnnoncementCreateType } from './types/AnnoncementTypes'
|
||||
import { AnnoncementCreateType, UserServiceItemType } from './types/AnnoncementTypes'
|
||||
import * as Yup from 'yup'
|
||||
import { ServiceItemType } from '../service/types/ServiceTypes'
|
||||
import { useCreateAnnoncement } from './hooks/useAnnoncementData'
|
||||
import { useCreateAnnoncement, useGetCustomersService } from './hooks/useAnnoncementData'
|
||||
import { ErrorType } from '../../helpers/types'
|
||||
import { toast } from 'react-toastify'
|
||||
import moment from 'moment-jalaali'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { Pages } from '../../config/Pages'
|
||||
|
||||
const Create: FC = () => {
|
||||
|
||||
const { t } = useTranslation('global')
|
||||
const navigate = useNavigate()
|
||||
const editorRef = useRef<HTMLDivElement | null>(null);
|
||||
const [serviceId, setServiceId] = useState('')
|
||||
const [customerId, setCustomerId] = useState<string>('')
|
||||
const getServices = useGetAllServices('', 1, '', '', false)
|
||||
const createAnnoncement = useCreateAnnoncement()
|
||||
const getCustomer = useGetCustomersService(serviceId)
|
||||
|
||||
const formik = useFormik<AnnoncementCreateType>({
|
||||
initialValues: {
|
||||
@@ -32,7 +38,8 @@ const Create: FC = () => {
|
||||
isPublic: false,
|
||||
isImportant: false,
|
||||
serviceId: '',
|
||||
groupIds: []
|
||||
groupIds: [],
|
||||
userIds: undefined
|
||||
},
|
||||
validationSchema: Yup.object({
|
||||
title: Yup.string().required(t('errors.required')),
|
||||
@@ -43,10 +50,15 @@ const Create: FC = () => {
|
||||
if (!values.serviceId) {
|
||||
values.serviceId = undefined
|
||||
}
|
||||
if (customerId) {
|
||||
values.serviceId = undefined
|
||||
values.userIds = [customerId]
|
||||
}
|
||||
createAnnoncement.mutate(values, {
|
||||
onSuccess: () => {
|
||||
formik.resetForm()
|
||||
toast.success(t('success'))
|
||||
navigate(Pages.announcement.list)
|
||||
},
|
||||
onError: (error: ErrorType) => {
|
||||
toast.error(error.response?.data?.error?.message[0])
|
||||
@@ -154,17 +166,21 @@ const Create: FC = () => {
|
||||
value: item.id
|
||||
})) || []}
|
||||
name='serviceId'
|
||||
onChange={formik.handleChange}
|
||||
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={[{
|
||||
label: 'Service 1',
|
||||
value: '1'
|
||||
}]}
|
||||
onChange={() => null}
|
||||
items={getCustomer?.data?.data?.users?.map((item: UserServiceItemType) => ({
|
||||
label: item.firstname + ' ' + item.lastname,
|
||||
value: item.id
|
||||
})) || []}
|
||||
onChange={(e) => setCustomerId(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -49,7 +49,7 @@ const AnnouncementtList: FC = () => {
|
||||
<tr>
|
||||
<Td text={t('announcement.title')} />
|
||||
<Td text={t('announcement.summary')} />
|
||||
<Td text={t('announcement.user')} />
|
||||
<Td text={t('announcement.service')} />
|
||||
<Td text={t('announcement.created_date')} />
|
||||
<Td text={t('announcement.publish_date')} />
|
||||
</tr>
|
||||
@@ -63,7 +63,7 @@ const AnnouncementtList: FC = () => {
|
||||
<Td text={''}>
|
||||
<p dangerouslySetInnerHTML={{ __html: item.content }}></p>
|
||||
</Td>
|
||||
<Td text={''} />
|
||||
<Td text={item?.targetService?.name} />
|
||||
<Td text={''}>
|
||||
<div className='dltr text-right'>
|
||||
{moment(item.createdAt).format('jYYYY-jMM-jDD HH:mm')}
|
||||
|
||||
@@ -26,3 +26,11 @@ export const useGetAnnoncementDetail = (id: string) => {
|
||||
queryFn: () => api.getAnnoncementDetail(id),
|
||||
});
|
||||
};
|
||||
|
||||
export const useGetCustomersService = (serviceId: string) => {
|
||||
return useQuery({
|
||||
queryKey: ["customer-service", serviceId],
|
||||
queryFn: () => api.getCustomerService(serviceId),
|
||||
enabled: !!serviceId,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -7,6 +7,11 @@ export const createAnnoncement = async (params: CreateAnnouncementType) => {
|
||||
return data;
|
||||
};
|
||||
|
||||
export const getCustomerService = async (serviceId: string) => {
|
||||
const { data } = await axios.get(`/danak-services/${serviceId}/users`);
|
||||
return data;
|
||||
};
|
||||
|
||||
export const getAnnoncements = async (
|
||||
page: number,
|
||||
search: string,
|
||||
|
||||
@@ -6,6 +6,7 @@ export type AnnoncementCreateType = {
|
||||
isImportant: boolean;
|
||||
serviceId?: string;
|
||||
groupIds: string[];
|
||||
userIds?: string[];
|
||||
};
|
||||
|
||||
export type AnnoncementItemType = {
|
||||
@@ -15,7 +16,18 @@ export type AnnoncementItemType = {
|
||||
publishAt: string;
|
||||
isPublic: boolean;
|
||||
isImportant: boolean;
|
||||
serviceId: string;
|
||||
groupIds: string[];
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
targetService: {
|
||||
id: string;
|
||||
name: string;
|
||||
};
|
||||
};
|
||||
|
||||
export type UserServiceItemType = {
|
||||
id: string;
|
||||
email: string;
|
||||
firstname: string;
|
||||
lastname: string;
|
||||
profilepic: string;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user