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