|
|
- |
+ |
+ |
|
|
|
@@ -86,6 +88,7 @@ const TicketList: FC = () => {
|
|
|
+ |
{moment(item.updatedAt).format('jYYYY-jMM-jDD HH:mm')}
diff --git a/src/pages/ticket/hooks/useTicketData.ts b/src/pages/ticket/hooks/useTicketData.ts
index 7587f58..00d044e 100644
--- a/src/pages/ticket/hooks/useTicketData.ts
+++ b/src/pages/ticket/hooks/useTicketData.ts
@@ -22,14 +22,15 @@ export const useGetCategoriesTicket = () => {
});
};
-export const useSingleUpload = () => {
+export const useSingleUpload = (callback?: (value: number) => void) => {
return useMutation({
- mutationFn: (variables: FormData) => api.uploadSingle(variables),
+ mutationFn: (variables: FormData) => api.uploadSingle(variables, callback),
});
};
-export const useMultiUpload = () => {
+export const useMultiUpload = (callback?: (value: number) => void) => {
return useMutation({
- mutationFn: (variables: FormData) => api.uploadMultiple(variables),
+ mutationFn: (variables: FormData) =>
+ api.uploadMultiple(variables, callback),
});
};
@@ -56,7 +57,16 @@ export const useAddMessageTicket = (id: string) => {
};
export const useCloseTicket = () => {
+ const queryClient = useQueryClient();
return useMutation({
mutationFn: (id: string) => api.closeTicket(id),
+ onSuccess: () => {
+ queryClient.refetchQueries({
+ queryKey: ["tickets"],
+ });
+ queryClient.refetchQueries({
+ queryKey: ["ticket-messages"],
+ });
+ },
});
};
diff --git a/src/pages/ticket/service/TicketService.ts b/src/pages/ticket/service/TicketService.ts
index 440f759..09fb041 100644
--- a/src/pages/ticket/service/TicketService.ts
+++ b/src/pages/ticket/service/TicketService.ts
@@ -2,7 +2,11 @@ import axios from "../../../config/axios";
import { AddMessageTicketType, CreateTicketType } from "../types/TicketTypes";
export const getTickets = async (status: string) => {
- const { data } = await axios.get(`/tickets?status=${status}`);
+ let query = ``;
+ if (status) {
+ query = `?status=${status}`;
+ }
+ const { data } = await axios.get(`/tickets${query}`);
return data;
};
@@ -16,13 +20,45 @@ export const getCategoriesTicket = async () => {
return data;
};
-export const uploadSingle = async (params: FormData) => {
- const { data } = await axios.post(`/uploader/single-file`, params);
+export const uploadSingle = async (
+ params: FormData,
+ callback?: (value: number) => void
+) => {
+ const { data } = await axios.post(`/uploader/single-file`, params, {
+ onUploadProgress: (progressEvent: any) => {
+ if (progressEvent.bytes) {
+ if (callback) {
+ callback(
+ Math.round((progressEvent.loaded / progressEvent.total) * 100)
+ );
+ }
+ }
+ },
+ });
+ if (callback) {
+ callback(0);
+ }
return data;
};
-export const uploadMultiple = async (params: FormData) => {
- const { data } = await axios.post(`/uploader/multi-file`, params);
+export const uploadMultiple = async (
+ params: FormData,
+ callback?: (value: number) => void
+) => {
+ const { data } = await axios.post(`/uploader/multi-file`, params, {
+ onUploadProgress: (progressEvent: any) => {
+ if (progressEvent.bytes) {
+ if (callback) {
+ callback(
+ Math.round((progressEvent.loaded / progressEvent.total) * 100)
+ );
+ }
+ }
+ },
+ });
+ if (callback) {
+ callback(0);
+ }
return data;
};
diff --git a/src/router/Main.tsx b/src/router/Main.tsx
index 1e6e274..fe48925 100644
--- a/src/router/Main.tsx
+++ b/src/router/Main.tsx
@@ -22,6 +22,9 @@ import { useGetSlugId } from "../pages/home/hooks/useHomeData"
import { ErrorType } from "../helpers/types"
import { toast } from "react-toastify"
import Request from "../pages/request/Request"
+import TicketList from "../pages/ticket/TicketList"
+import TicketCreate from "../pages/ticket/CreateTicket"
+import TicketDetail from "../pages/ticket/Detail"
const MainRouter = () => {
const { slug } = useParams()
const getSlugId = useGetSlugId()
@@ -71,6 +74,9 @@ const MainRouter = () => {
} />
} />
} />
+ } />
+ } />
+ } />
|