diff --git a/src/Pages/IO_Management/CreateIO/IOArtifacts.jsx b/src/Pages/IO_Management/CreateIO/IOArtifacts.jsx
index f90f6cb..bacb66c 100644
--- a/src/Pages/IO_Management/CreateIO/IOArtifacts.jsx
+++ b/src/Pages/IO_Management/CreateIO/IOArtifacts.jsx
@@ -303,6 +303,11 @@ const IOArtifacts = ({ enableNextTab, index, data }) => {
color="blue.400"
rounded={"sm"}
size={"xs"}
+
+ onClick={()=>{
+ setActionId(item?.id)
+ onOpenVideo()
+ }}
>
@@ -353,15 +358,13 @@ const IOArtifacts = ({ enableNextTab, index, data }) => {
@@ -396,6 +399,12 @@ const IOArtifacts = ({ enableNextTab, index, data }) => {
isOpen={isOpenVideo}
onClose={onCloseVideo}
secondField={secondField}
+
+
+
+ actionId={actionId}
+ setActionId={setActionId}
+ data={IObyID?.data?.artifactsVideo}
/>
{
+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: () => ,
- });
- setAlert(false);
- setIsLoading(false)
- handleClose();
+
+
+ if (found) {
+ const res = await updateVideoArtifacts({data, id: found?.id})
+ if (res?.data?.statusCode === 200) {
+ toast({
+ render: () => ,
+ });
+ setAlert(false);
+ setIsLoading(false)
+ handleClose();
+ }
+ } else {
+
+ const res = await createArtifactsVideo({data, id})
+ if (res?.data?.statusCode === 200) {
+ toast({
+ render: () => ,
+ });
+ setAlert(false);
+ setIsLoading(false)
+ handleClose();
+ }
+
}
@@ -88,6 +127,7 @@ const IOArtifactsAdd = ({ isOpen, onClose, firstField }) => {
const handleClose = () => {
onClose()
reset()
+ setActionId(false);
}
return (
diff --git a/src/Pages/IO_Management/IOArtifactsAdd.jsx b/src/Pages/IO_Management/IOArtifactsAdd.jsx
index e104311..355a076 100644
--- a/src/Pages/IO_Management/IOArtifactsAdd.jsx
+++ b/src/Pages/IO_Management/IOArtifactsAdd.jsx
@@ -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: () => ,
+ render: () => (
+
+ ),
});
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}
- {preview && }
- {found && !preview && }
+ {preview && (
+
+ )}
+ {found && !preview && (
+
+ )}
@@ -275,4 +277,4 @@ const IOArtifactsAdd = ({
);
};
-export default IOArtifactsAdd;
+export default IOArtifactsAdd;
\ No newline at end of file
diff --git a/src/Services/api.service.js b/src/Services/api.service.js
index 2649cc9..cbfe4d4 100644
--- a/src/Services/api.service.js
+++ b/src/Services/api.service.js
@@ -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",
diff --git a/src/Services/io.service.js b/src/Services/io.service.js
index 3b1de9b..65dc28d 100644
--- a/src/Services/io.service.js
+++ b/src/Services/io.service.js
@@ -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,