This commit is contained in:
@@ -1,75 +1,73 @@
|
|||||||
import { FC, useState } from 'react'
|
import { FC, useState } from "react";
|
||||||
import { useGetUsers } from '../../users/hooks/useUserData'
|
import { useTranslation } from "react-i18next";
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useParams } from "react-router-dom";
|
||||||
import { UserItemType } from '../../users/types/UserTypes'
|
import Button from "../../../components/Button";
|
||||||
import CheckBoxComponent from '../../../components/CheckBoxComponent'
|
import CheckBoxComponent from "../../../components/CheckBoxComponent";
|
||||||
import { useParams } from 'react-router-dom'
|
import { toast } from "../../../components/Toast";
|
||||||
import { useReferTicket } from '../hooks/useTicketData'
|
import { ErrorType } from "../../../helpers/types";
|
||||||
import Button from '../../../components/Button'
|
import { useGetAdminsListAll } from "../../users/hooks/useUserData";
|
||||||
import { toast } from '../../../components/Toast';
|
import { UserItemType } from "../../users/types/UserTypes";
|
||||||
import { ErrorType } from '../../../helpers/types'
|
import { useReferTicket } from "../hooks/useTicketData";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
refetch: () => void
|
refetch: () => void;
|
||||||
}
|
};
|
||||||
|
|
||||||
const ReferTicket: FC<Props> = ({ refetch }) => {
|
const ReferTicket: FC<Props> = ({ refetch }) => {
|
||||||
|
const { t } = useTranslation("global");
|
||||||
|
const { id } = useParams();
|
||||||
|
const [userId, setUserId] = useState<string>("");
|
||||||
|
const getUsers = useGetAdminsListAll();
|
||||||
|
const referTicket = useReferTicket();
|
||||||
|
|
||||||
const { t } = useTranslation('global')
|
const handleReferTicket = () => {
|
||||||
const { id } = useParams()
|
referTicket.mutate(
|
||||||
const [userId, setUserId] = useState<string>('')
|
{ id: id as string, userId },
|
||||||
const getUsers = useGetUsers('', 'tickets')
|
{
|
||||||
const referTicket = useReferTicket()
|
onSuccess: () => {
|
||||||
|
refetch();
|
||||||
|
toast(t("ticket.refer_ticket_success"), "success");
|
||||||
|
},
|
||||||
|
onError: (error: ErrorType) => {
|
||||||
|
toast(error.response?.data?.error.message[0], "error");
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const handleReferTicket = () => {
|
return (
|
||||||
referTicket.mutate({ id: id as string, userId }, {
|
<div className={"bg-white p-6 rounded-3xl mt-8"}>
|
||||||
onSuccess: () => {
|
<div className="flex justify-between">
|
||||||
refetch()
|
<div className="text-sm">{t("ticket.refer_ticket")}</div>
|
||||||
toast(t('ticket.refer_ticket_success'), 'success')
|
</div>
|
||||||
},
|
|
||||||
onError: (error: ErrorType) => {
|
|
||||||
toast(error.response?.data?.error.message[0], 'error')
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
<div className="mt-4">
|
||||||
<div className={'bg-white p-6 rounded-3xl mt-8'}>
|
{getUsers.data?.data?.map((item: UserItemType) => (
|
||||||
<div className='flex justify-between'>
|
<div
|
||||||
<div className='text-sm'>
|
key={item.id}
|
||||||
{t('ticket.refer_ticket')}
|
className="flex gap-2 items-center"
|
||||||
</div>
|
>
|
||||||
</div>
|
<div>
|
||||||
|
<CheckBoxComponent
|
||||||
<div className="mt-4">
|
checked={userId === item.id}
|
||||||
{
|
onChange={(e) => setUserId(e.target.checked ? item.id : "")}
|
||||||
getUsers.data?.data?.users?.map((item: UserItemType) => (
|
/>
|
||||||
<div key={item.id} className='flex gap-2 items-center'>
|
|
||||||
<div>
|
|
||||||
<CheckBoxComponent
|
|
||||||
checked={userId === item.id}
|
|
||||||
onChange={(e) => setUserId(e.target.checked ? item.id : '')}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div className='text-xs leading-5'>
|
|
||||||
{item.firstName + ' ' + item.lastName}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
<div className='flex justify-end mt-4'>
|
|
||||||
<Button
|
|
||||||
label={t('ticket.refer_ticket')}
|
|
||||||
onClick={handleReferTicket}
|
|
||||||
isLoading={referTicket.isPending}
|
|
||||||
className='w-fit px-7'
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
<div className="text-xs leading-5">{item.firstName + " " + item.lastName}</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
|
||||||
|
<div className="flex justify-end mt-4">
|
||||||
|
<Button
|
||||||
|
label={t("ticket.refer_ticket")}
|
||||||
|
onClick={handleReferTicket}
|
||||||
|
isLoading={referTicket.isPending}
|
||||||
|
className="w-fit px-7"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
)
|
</div>
|
||||||
}
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
export default ReferTicket
|
export default ReferTicket;
|
||||||
|
|||||||
Reference in New Issue
Block a user