From 2071e78a6544780b2b3822a200e02bfe7ace0061 Mon Sep 17 00:00:00 2001 From: Bart K Date: Fri, 22 Nov 2024 09:46:46 +0100 Subject: [PATCH] fix(portal): add post push history creation --- .../PushHistoryModal/index.test.tsx | 1 - .../src/hooks/product/index.ts | 2 +- .../src/hooks/pushApiEvent/index.ts | 31 +++++++++++++---- .../components/PushHistoryModal/index.tsx | 33 ++++++++++++++----- .../pages/EnvironmentActivityLog/index.tsx | 1 - .../src/services/pushApiActivity.ts | 10 ++++++ .../src/utils/types/common.type.ts | 6 ++++ 7 files changed, 66 insertions(+), 18 deletions(-) diff --git a/kraken-app/kraken-app-portal/src/__test__/pages/EnvironmentActivityLog/PushHistoryModal/index.test.tsx b/kraken-app/kraken-app-portal/src/__test__/pages/EnvironmentActivityLog/PushHistoryModal/index.test.tsx index 5976300c..886eb369 100644 --- a/kraken-app/kraken-app-portal/src/__test__/pages/EnvironmentActivityLog/PushHistoryModal/index.test.tsx +++ b/kraken-app/kraken-app-portal/src/__test__/pages/EnvironmentActivityLog/PushHistoryModal/index.test.tsx @@ -11,7 +11,6 @@ test("PushHistoryModal", () => { { return useQuery>({ // TODO: type push history - queryKey: [PRODUCT_CACHE_KEYS.get_product_env_list], + queryKey: [PUSH_API_EVENT_CACHE_KEYS.get_product_env_list], queryFn: () => getPushEventHistory(), select: (data) => data.data, staleTime: STALE_TIME, }); -} \ No newline at end of file +} + +export const usePostPushActivityLog = () => { + return useMutation({ + mutationKey: [PUSH_API_EVENT_CACHE_KEYS.create_activity_history_log], + mutationFn: (data) => { + return createActivityHistoryLog(data); + }, + onSuccess: () => { + queryClient.invalidateQueries({ + queryKey: [PUSH_API_EVENT_CACHE_KEYS.create_activity_history_log], + }); + }, + }); +}; \ No newline at end of file diff --git a/kraken-app/kraken-app-portal/src/pages/EnvironmentActivityLog/components/PushHistoryModal/index.tsx b/kraken-app/kraken-app-portal/src/pages/EnvironmentActivityLog/components/PushHistoryModal/index.tsx index b89fd2a1..b54a0e4e 100644 --- a/kraken-app/kraken-app-portal/src/pages/EnvironmentActivityLog/components/PushHistoryModal/index.tsx +++ b/kraken-app/kraken-app-portal/src/pages/EnvironmentActivityLog/components/PushHistoryModal/index.tsx @@ -6,13 +6,15 @@ import dayjs from 'dayjs'; import { useGetProductEnvActivitiesMutation } from '@/hooks/product'; import { disabled7DaysDate } from '@/utils/helpers/date'; import { useAppStore } from "@/stores/app.store"; +import { usePostPushActivityLog } from '@/hooks/pushApiEvent'; +import { ICreateActivityHistoryLogRequest } from '@/utils/types/common.type'; +import { TIME_ZONE_FORMAT } from '@/utils/constants/format'; const { RangePicker } = DatePicker; type Props = { isOpen: boolean; onClose: () => void; - onOK: (value: string) => void; envOptions: Array<{ value: string; label: string; @@ -22,19 +24,32 @@ type Props = { const PushHistoryModal = ({ isOpen, onClose, - onOK, envOptions, }: Props) => { const [form] = Form.useForm(); const { currentProduct } = useAppStore(); + const { data: responseData, mutateAsync: getProductEnvActivities, isPending, isSuccess } = useGetProductEnvActivitiesMutation(); + const { mutateAsync: createPushActivityLog } = usePostPushActivityLog(); + const handleOK = () => { - // TODO: - onOK(form.getFieldsValue()); + createPushActivityLog(parseParams()) + onClose(); }; - const { data: responseData, mutateAsync, isPending, isSuccess } = useGetProductEnvActivitiesMutation(); - + const parseParams = () : ICreateActivityHistoryLogRequest => { + const { envId, requestTime } = form.getFieldsValue(); + return { + startTime: requestTime?.[0] + ? dayjs(requestTime[0]).startOf("day").format(TIME_ZONE_FORMAT) + : undefined, + endTime: requestTime?.[1] + ? dayjs(requestTime[1]).endOf("day").format(TIME_ZONE_FORMAT) + : undefined, + envId + }; + } + const handleFormValuesChange = useCallback( (t: any, values: any) => { if (t.path) return; @@ -42,15 +57,15 @@ const PushHistoryModal = ({ const params = { requestStartTime: requestTime?.[0] - ? dayjs(requestTime[0]).startOf("day").valueOf() + ? dayjs(requestTime[0]).startOf("day").format(TIME_ZONE_FORMAT) : undefined, requestEndTime: requestTime?.[1] - ? dayjs(requestTime[1]).endOf("day").valueOf() + ? dayjs(requestTime[1]).endOf("day").format(TIME_ZONE_FORMAT) : undefined } if (values.envId && !!params.requestStartTime) { - mutateAsync({ + getProductEnvActivities({ productId: currentProduct, envId: values.envId, params diff --git a/kraken-app/kraken-app-portal/src/pages/EnvironmentActivityLog/index.tsx b/kraken-app/kraken-app-portal/src/pages/EnvironmentActivityLog/index.tsx index bdf0eeb1..6b8338b8 100644 --- a/kraken-app/kraken-app-portal/src/pages/EnvironmentActivityLog/index.tsx +++ b/kraken-app/kraken-app-portal/src/pages/EnvironmentActivityLog/index.tsx @@ -202,7 +202,6 @@ const EnvironmentActivityLog = () => { isOpen={isOpen} envOptions={envOptions} onClose={close} - onOK={() => alert('OK')} /> )} diff --git a/kraken-app/kraken-app-portal/src/services/pushApiActivity.ts b/kraken-app/kraken-app-portal/src/services/pushApiActivity.ts index adc54f50..83f2aba6 100644 --- a/kraken-app/kraken-app-portal/src/services/pushApiActivity.ts +++ b/kraken-app/kraken-app-portal/src/services/pushApiActivity.ts @@ -1,5 +1,15 @@ import request from "@/utils/helpers/request"; import { PUSH_API_ACTIVITY } from "@/utils/constants/api"; +import { ICreateActivityHistoryLogRequest } from '@/utils/types/common.type'; export const getPushEventHistory = () => request(`${PUSH_API_ACTIVITY}/history`); + +export const createActivityHistoryLog = (payload: ICreateActivityHistoryLogRequest) => { + return request(PUSH_API_ACTIVITY, { + method: "POST", + data: { + ...payload, + }, + }); +}; diff --git a/kraken-app/kraken-app-portal/src/utils/types/common.type.ts b/kraken-app/kraken-app-portal/src/utils/types/common.type.ts index e1934408..e8f52a4a 100644 --- a/kraken-app/kraken-app-portal/src/utils/types/common.type.ts +++ b/kraken-app/kraken-app-portal/src/utils/types/common.type.ts @@ -64,6 +64,12 @@ export interface IEndpointUsageAsset { }; } +export interface ICreateActivityHistoryLogRequest { + startTime?: string; + endTime?: string; + envId?: string; +}; + export enum EnumRightType { SelectSellerAPI, AddSonataProp,