This commit is contained in:
2024-07-31 12:14:13 +05:30
parent fe9f7ac94e
commit db8ed99c9b
6 changed files with 119 additions and 96 deletions

View File

@@ -132,7 +132,7 @@ const ViewIOdataHeader = () => {
h={"100%"}
w={"100%"}
objectFit={'cover'}
src={" https://admin.tanami.betadelivery.com/" + IODetails?.artifactsImage?.[0]?.artifactPathName}
src={" https://tanami.betadelivery.com/" + IODetails?.artifactsImage?.[0]?.artifactPathName}
alt={IODetails?.ioName}
/>
) : (

View File

@@ -14,6 +14,7 @@ import {
Text,
Tooltip,
useDisclosure,
useToast,
} from "@chakra-ui/react";
import React, { useContext, useRef, useState, useEffect } from "react";
import GlobalStateContext from "../../../Contexts/GlobalStateContext";
@@ -22,6 +23,9 @@ import { FiEdit3 } from "react-icons/fi";
import { BiMessageSquareEdit } from "react-icons/bi";
import { TbEdit } from "react-icons/tb";
import { EditIcon, ViewIcon } from "@chakra-ui/icons";
import { formatDate } from "../../../Components/Functions/UTCConvertor";
import { useGetExchangeRateByIdQuery, useUpdateExchangeRateMutation } from "../../../Services/exchange.rate.service";
import ToastBox from "../../../Components/ToastBox";
// Convert date to YYYY-MM-DD format
const formatDateValue = (date) => {
@@ -39,70 +43,84 @@ const formatDateValue = (date) => {
const EditExchangeRate = ({ id, setIsLoading, updateHistory }) => {
const btnRef = useRef();
const toast = useToast();
const { isOpen, onOpen, onClose } = useDisclosure();
const { rateExchange, setRateExchange } = useContext(GlobalStateContext);
const [ isBtnLoading, setIsBtnLoading ] = useState(false)
const foundObject = rateExchange.find((item) => item.id === id);
const { data, isLoading, errors } = useGetExchangeRateByIdQuery(id, {
skip: !id,
});
const [effectFrom, setEffectFrom] = useState("");
const [effectTill, setEffectTill] = useState("");
const [rate, setRate] = useState("");
const [ updateExchange ] = useUpdateExchangeRateMutation()
const foundObject = data?.data;
const [rate, setRate] = useState("");
const [alert, setAlert] = useState(false);
useEffect(() => {
if (foundObject) {
setEffectFrom(formatDateValue(foundObject.effectFrom));
setEffectTill(formatDateValue(foundObject.effectTill));
setRate(foundObject.rate);
}
}, [foundObject]);
const handleSave = () => {
setIsLoading(true);
const previousRate = foundObject.rate;
const updatedExchange = rateExchange.map((item) =>
item.id === id
? {
...item,
effectFrom: new Date(effectFrom),
effectTill: new Date(effectTill),
rate: parseFloat(rate),
}
: item
);
setTimeout(() => {
setRateExchange(updatedExchange);
updateHistory(id, previousRate, parseFloat(rate), new Date(effectFrom));
setIsLoading(false);
setAlert(false);
onClose();
}, 100);
setIsLoading(true);
const handleSave = async () => {
setIsBtnLoading(true)
try {
const data = {
rate: rate
}
const res = await updateExchange({data, id})
console.log(res?.data?.statusCode);
if (res?.data?.statusCode === 200) {
console.log("hit");
toast({
render: () => <ToastBox message={res?.data?.message} />,
});
setIsBtnLoading(false)
setAlert(false)
onClose()
}
} catch (error) {
}
};
return (
<> <Tooltip
rounded={"sm"}
fontSize={"xs"}
label="Edit"
bg="#fff"
color={"blue.500"}
placement="top"
>
<Button
ref={btnRef}
onClick={onOpen}
_hover={{ color: "blue.500" }}
// transition={"0.5s all"}
color="blue.400"
size={"xs"}
<>
{" "}
<Tooltip
rounded={"sm"}
fontSize={"xs"}
label="Edit"
bg="#fff"
color={"blue.500"}
placement="top"
>
<EditIcon />
</Button>
<Button
ref={btnRef}
onClick={onOpen}
_hover={{ color: "blue.500" }}
// transition={"0.5s all"}
color="blue.400"
size={"xs"}
// size={{base:'xs', lg:'sm'}}
rounded={"sm"}
display={"flex"}
alignItems={"center"}
gap={1}
>
<EditIcon /> Update
</Button>
</Tooltip>
<Drawer
size={"md"}
size={"md"}
isOpen={isOpen}
placement="right"
onClose={onClose}
@@ -118,36 +136,20 @@ const EditExchangeRate = ({ id, setIsLoading, updateHistory }) => {
<Box w={"50%"} display={"flex"} flexDirection={"column"} gap={1}>
<FormLabel fontSize={"sm"}>From</FormLabel>
<Text as={"span"} fontSize={"sm"} fontWeight={"bold"}>
{foundObject?.fromCurr}
{foundObject?.fromCurrency_xid}
</Text>
</Box>
<Box w={"50%"} display={"flex"} flexDirection={"column"} gap={1}>
<FormLabel fontSize={"sm"}>To</FormLabel>
<Text as={"span"} fontSize={"sm"} fontWeight={"bold"}>
{foundObject?.toCurr}
{foundObject?.toCurrency_xid}
</Text>
</Box>
</Box>
<FormControl mb={4}>
<FormLabel fontSize={"sm"}>Effective from</FormLabel>
<Input
value={effectFrom}
onChange={(e) => setEffectFrom(e.target.value)}
fontSize={"sm"}
type="date"
size={"sm"}
/>
</FormControl>
<FormControl mb={4}>
<FormLabel fontSize={"sm"}>Effective to</FormLabel>
<Input
value={effectTill}
onChange={(e) => setEffectTill(e.target.value)}
type="date"
size={"sm"}
/>
<Text fontSize={"sm"}>{formatDate(foundObject?.effectiveFrom)}</Text>
</FormControl>
<FormControl mb={4}>
@@ -185,12 +187,12 @@ const EditExchangeRate = ({ id, setIsLoading, updateHistory }) => {
</DrawerFooter>
</DrawerContent>
</Drawer>
<CustomAlertDialog
isOpen={alert}
onClose={() => setAlert(false)}
alertHandler={handleSave}
message={"Are you sure you want to update rates?"}
isLoading={isBtnLoading}
/>
</>
);

View File

@@ -100,9 +100,15 @@ const ExchangeHistory = ({ id, setIsLoading, history }) => {
// transition={"0.5s all"}
color="purple.400"
rounded={"sm"}
size={"xs"}
size={{base:'xs', lg:'xs'}}
display={'flex'}
alignItems={'center'}
gap={1}
>
<MdHistory />
<MdHistory /> View history
</Button>
</Tooltip>
<Drawer

View File

@@ -30,6 +30,8 @@ import ToastBox from "../../../Components/ToastBox";
import { formatDate } from "../../../Components/Functions/UTCConvertor";
import EditExchangeRate from "./EditExchangeRate";
import ExchangeHistory from "./ExchangeHistroy";
import { useGetAllExchangeRatesQuery } from "../../../Services/exchange.rate.service";
import { TABLE_PAGINATION } from "../../../Constants/Paginations";
const ExchangeRate = () => {
const toast = useToast();
@@ -43,6 +45,18 @@ const ExchangeRate = () => {
const [mouseEnteredId, setMouseEnteredId] = useState("");
const [history, setHistory] = useState([]);
// ===============================[ Paginations ]
const [pageSize, setPageSize] = useState(TABLE_PAGINATION?.size);
const [currentPage, setCurrentPage] = useState(1);
const {
data,
isLoading: isExchangeRateLoading,
errors,
} = useGetAllExchangeRatesQuery({ page: currentPage, size: pageSize })
console.log(data?.data);
useEffect(() => {
// Simulate loading
const timer = setTimeout(() => {
@@ -85,12 +99,11 @@ const ExchangeRate = () => {
"From currency",
"To currency",
"Effective from",
"Effective till",
"Rate",
"Action",
];
const extractedArray = filteredData?.map((item, index) => ({
const extractedArray = data?.data?.map((item, index) => ({
"Sr.No": (
<Text
justifyContent={slideFromRight ? "right" : "left"}
@@ -110,7 +123,7 @@ const ExchangeRate = () => {
fontWeight={"600"}
className="d-flex align-items-center fw- web-text-small"
>
{item.fromCurr}
{item.fromCurrency_xid}
</Text>
),
"To currency": (
@@ -121,7 +134,7 @@ const ExchangeRate = () => {
fontWeight={"600"}
className="d-flex align-items-center fw- web-text-small"
>
{item.toCurr}
{item.toCurrency_xid}
</Text>
),
"Effective from": (
@@ -132,18 +145,7 @@ const ExchangeRate = () => {
fontWeight={"600"}
className="d-flex align-items-center web-text-small"
>
{formatDate(item.effectFrom)}
</Text>
),
"Effective till": (
<Text
justifyContent={slideFromRight ? "right" : "left"}
as={"span"}
color={"gray.600"}
fontWeight={"600"}
className="d-flex align-items-center web-text-small"
>
{formatDate(item.effectTill)}
{formatDate(item.effectiveFrom)}
</Text>
),
Rate: (

View File

@@ -1,22 +1,41 @@
// exchangeRate.service.js
import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react";
import { api } from "./api.service";
const baseUrl = import.meta.env.VITE_API_BASE_URL + "/api";
const baseUrl = api?.defaults.baseURL;
// Define a service using a base URL and expected endpoints
export const exchangeRate = createApi({
reducerPath: "exchangeRate",
baseQuery: fetchBaseQuery({ baseUrl }),
tagTypes: [],
tagTypes: ["getAllExchangeRate", "getExchangeById"],
endpoints: (builder) => ({
getExchangeRates: builder.query({
query: () => '/getExchangeRates',
getAllExchangeRates: builder.query({
query: ({ page, size }) =>
`/currencyExchange/admin?page=${page}&size=${size}`,
providesTags: ["getAllExchangeRate"],
}),
getExchangeRateById: builder.query({
query: (id) => `/getExchangeRate/${id}`,
query: (id) => `/currencyExchange/admin/${id}`,
providesTags: ["getAllExchangeRate"],
}),
updateExchangeRate: builder.mutation({
query: ({ data, id }) => ({
url: `/currencyExchange/admin/${id}`,
method: "PATCH",
body: data,
}),
invalidatesTags: ["getAllExchangeRate"],
}),
}),
});
// Export hooks for usage in functional components
export const { useGetExchangeRatesQuery, useGetExchangeRateByIdQuery } = exchangeRate;
export const {
useGetAllExchangeRatesQuery,
useGetExchangeRateByIdQuery,
useUpdateExchangeRateMutation,
} = exchangeRate;

View File

@@ -198,12 +198,6 @@ export const ioService = createApi({
}),
invalidatesTags: ["getIOById"],
}),
updateStatusIo: builder.mutation({
query: ({ data, id }) => ({