This commit is contained in:
YasinShaikh123
2024-07-30 19:36:01 +05:30
5 changed files with 115 additions and 51 deletions

View File

@@ -303,6 +303,11 @@ const IOArtifacts = ({ enableNextTab, index, data }) => {
color="blue.400"
rounded={"sm"}
size={"xs"}
onClick={()=>{
setActionId(item?.id)
onOpenVideo()
}}
>
<EditIcon />
</Button>
@@ -353,15 +358,13 @@ const IOArtifacts = ({ enableNextTab, index, data }) => {
</Button>
</HStack>
<IOArtifactsAdd
actionId={actionId}
isOpen={isOpen}
onClose={onClose}
firstField={firstField}
actionId={actionId}
setActionId={setActionId}
data={IObyID?.data?.artifactsImage}
/>
</Box>
@@ -396,6 +399,12 @@ const IOArtifacts = ({ enableNextTab, index, data }) => {
isOpen={isOpenVideo}
onClose={onCloseVideo}
secondField={secondField}
actionId={actionId}
setActionId={setActionId}
data={IObyID?.data?.artifactsVideo}
/>
</Box>
<DataTable

View File

@@ -16,12 +16,12 @@ import {
useToast,
} from "@chakra-ui/react";
import * as yup from "yup";
import React, { useState } from "react";
import React, { useState, useEffect } from "react";
import { useForm, Controller } from "react-hook-form";
import { yupResolver } from "@hookform/resolvers/yup";
import CustomAlertDialog from "../../../Components/CustomAlertDialog";
import { v4 as uuidv4 } from "uuid";
import { useCreateVideoArtifactsMutation, useDeleteVideoArtifactsMutation } from "../../../Services/io.service";
import { useCreateVideoArtifactsMutation, useUpdateVideoArtifactsMutation } from "../../../Services/io.service";
import { useParams } from "react-router-dom";
import ToastBox from "../../../Components/ToastBox";
@@ -30,7 +30,7 @@ const investmentVideoSchema = yup.object().shape({
artifactStreamingURL: yup.string().required("Artifact streaming URL is required").url("Invalid URL format"),
});
const IOArtifactsAdd = ({ isOpen, onClose, firstField }) => {
const IOArtifactsAdd = ({ isOpen, onClose, firstField, actionId, setActionId, data}) => {
const params = useParams()
const id = params?.id
const [file, setFile] = useState("");
@@ -39,7 +39,12 @@ const IOArtifactsAdd = ({ isOpen, onClose, firstField }) => {
const [alert, setAlert] = useState(false);
const toast = useToast();
const found = data?.find((item) => item?.id === actionId);
console.log(found);
const [ createArtifactsVideo ] = useCreateVideoArtifactsMutation()
const [ updateVideoArtifacts ] = useUpdateVideoArtifactsMutation()
// const {
// data
// } = useGetArtifactsQuery(id)
@@ -47,24 +52,58 @@ const IOArtifactsAdd = ({ isOpen, onClose, firstField }) => {
const {
control,
handleSubmit,
watch,
reset,
formState: { errors },
} = useForm({
resolver: yupResolver(investmentVideoSchema),
});
// useEffect to reset the form when `found` changes
useEffect(() => {
if (found) {
reset({
artifactName: found?.artifactName,
artifactStreamingURL: found?.artifactStreamingURL,
});
}
}, [found, reset]);
console.log(watch());
const onSubmit = async (data) => {
setIsLoading(true)
try {
const res = await createArtifactsVideo({data, id})
if (res?.data?.statusCode === 200) {
toast({
render: () => <ToastBox message={res?.data?.message} />,
});
setAlert(false);
setIsLoading(false)
handleClose();
if (found) {
const res = await updateVideoArtifacts({data, id: found?.id})
if (res?.data?.statusCode === 200) {
toast({
render: () => <ToastBox message={res?.data?.message} />,
});
setAlert(false);
setIsLoading(false)
handleClose();
}
} else {
const res = await createArtifactsVideo({data, id})
if (res?.data?.statusCode === 200) {
toast({
render: () => <ToastBox message={res?.data?.message} />,
});
setAlert(false);
setIsLoading(false)
handleClose();
}
}
@@ -88,6 +127,7 @@ const IOArtifactsAdd = ({ isOpen, onClose, firstField }) => {
const handleClose = () => {
onClose()
reset()
setActionId(false);
}
return (

View File

@@ -21,7 +21,10 @@ import React, { useEffect, useState } from "react";
import { useForm, Controller } from "react-hook-form";
import { yupResolver } from "@hookform/resolvers/yup";
import CustomAlertDialog from "../../Components/CustomAlertDialog";
import { useCreateImageArtifactsMutation, useUpdateImageArtifactsMutation } from "../../Services/io.service";
import {
useCreateImageArtifactsMutation,
useUpdateImageArtifactsMutation,
} from "../../Services/io.service";
import { useParams } from "react-router-dom";
import ToastBox from "../../Components/ToastBox";
@@ -49,7 +52,7 @@ const IOArtifactsAdd = ({
const toast = useToast();
const [createImageArtifacts] = useCreateImageArtifactsMutation();
const [ updateImageArtifacts ] = useUpdateImageArtifactsMutation()
const [updateImageArtifacts] = useUpdateImageArtifactsMutation();
const found = data?.find((item) => item?.id === actionId);
console.log(found);
@@ -77,14 +80,12 @@ const IOArtifactsAdd = ({
console.log(watch());
const onSubmit = async (data) => {
setIsLoading(true);
const formData = new FormData();
formData.append("artifactName", data.artifactName);
formData.append("artifactPathName", file); // Assuming artifactPathName is an array of files
file && formData.append("artifactPathName", file); // Assuming artifactPathName is an array of files
console.log("FormData:", formData);
for (let [key, value] of formData.entries()) {
@@ -92,11 +93,11 @@ const IOArtifactsAdd = ({
}
try {
if(found){
const res = await updateImageArtifacts({ data: formData, id: found?.id });
if (found) {
const res = await updateImageArtifacts({
data: formData,
id: found?.id,
});
console.log(res?.error);
if (res?.data?.statusCode === 200) {
toast({
@@ -110,22 +111,16 @@ const IOArtifactsAdd = ({
onClose();
}
if(res?.error){
if (res?.error) {
toast({
render: () => <ToastBox message={res?.error?.data?.message} status={'error'} />,
render: () => (
<ToastBox message={res?.error?.data?.message} status={"error"} />
),
});
reset();
setIsLoading(false);
}
}else{
} else {
const res = await createImageArtifacts({ data: formData, id });
if (res?.data?.statusCode === 200) {
toast({
@@ -138,17 +133,7 @@ const IOArtifactsAdd = ({
setPreview(null);
onClose();
}
}
} catch (error) {
console.log(error);
}
@@ -179,7 +164,7 @@ const IOArtifactsAdd = ({
artifactName: "",
artifactPathName: "",
});
onClose();
setActionId(false);
};
@@ -235,8 +220,25 @@ const IOArtifactsAdd = ({
errors.artifactPathName?.message &&
errors.artifactPathName?.message}
</FormErrorMessage>
{preview && <Image rounded={'md'} src={preview} alt="Image Preview" mt={2} />}
{found && !preview && <Image rounded={'md'} src={"https://admin.tanami.betadelivery.com/"+watch()?.artifactPathName} alt="Image Preview" mt={2} />}
{preview && (
<Image
rounded={"md"}
src={preview}
alt="Image Preview"
mt={2}
/>
)}
{found && !preview && (
<Image
rounded={"md"}
src={
"https://admin.tanami.betadelivery.com/" +
watch()?.artifactPathName
}
alt="Image Preview"
mt={2}
/>
)}
</FormControl>
</Stack>
</DrawerBody>
@@ -275,4 +277,4 @@ const IOArtifactsAdd = ({
);
};
export default IOArtifactsAdd;
export default IOArtifactsAdd;

View File

@@ -2,7 +2,8 @@ import axios from "axios";
// Create an Axios instance for API calls
export const api = axios.create({
baseURL: `https://admin.tanami.betadelivery.com/api/v1`, // Replace with your API base URL
// baseURL: `https://admin.tanami.betadelivery.com/api/v1`,
baseURL: `https://tanami.betadelivery.com/api/v1`, // Replace with your API base URL
timeout: 10000, // Adjust timeout as needed
headers: {
"Content-Type": "application/json",

View File

@@ -179,6 +179,17 @@ export const ioService = createApi({
invalidatesTags: ["getIOById"],
}),
updateVideoArtifacts: builder.mutation({
query: ({ data, id }) => ({
url: `/io/artifact/video/${id}`,
method: "PATCH",
body: data,
}),
invalidatesTags: ["getIOById"],
}),
setDisplayOrder: builder.mutation({
query: ({ data }) => ({
url: `/io/artifact/artifactImage/resetDisplayOrder/`,
@@ -236,6 +247,7 @@ export const {
useCreateImageArtifactsMutation,
useUpdateImageArtifactsMutation,
useUpdateVideoArtifactsMutation,
useGetArtifactsVideoQuery,
useCreateVideoArtifactsMutation,