Skip to content

Commit

Permalink
new day
Browse files Browse the repository at this point in the history
  • Loading branch information
NITISH1018 committed Nov 26, 2023
1 parent b4d83c9 commit 358ebee
Show file tree
Hide file tree
Showing 4 changed files with 239 additions and 125 deletions.
162 changes: 105 additions & 57 deletions client/src/screens/allcategories/livetvcategories/addcategory.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useState } from "react";

import React, { useState,useEffect } from "react";
import axios from "axios"
import { useParams } from "react-router-dom";
import {
TextField,
Button,
Expand All @@ -11,6 +12,9 @@ import {
FormControlLabel,
Checkbox,
Box,
Snackbar,
Alert,
useMediaQuery
} from "@mui/material";
import FlexBetween from "components/FlexBetween";
import Header from "components/Header";
Expand All @@ -22,70 +26,100 @@ import SidebarAllCategories from "components/SidebarAllCategories";
const AddCategoryLiveTv = () => {
const [passchecked, setPassChecked] = useState(false);
const [visiblechecked, setVisibleChecked] = useState(false);

const isSmallScreen = useMediaQuery("(max-width: 600px)");
const { _id } = useParams();
const [formData, setFormData] = useState({
title: "",
});

// visible: '',

// stream_for_webtv: '',

// stream_for_ios_mobile: '',

// stream_for_android: '',

// android_setup_box: '',

// custom_linux_box: '',

// dreambox: '',

// pc: '',

// add_trailer: '',

// description: '',

// language: '',

// duration: '',

// year: '',

// studio: '',

// producer:'',

// director: '',

// actors: '',

// ratings: '',

// price: '',
const handleReset = () => {
setFormData({
title:"",

});
};

// select_channel_image: '',
const [successMessage, setSuccessMessage] = useState("");
const [snackbarOpen, setSnackbarOpen] = useState(false);

// category: ''
});

const handleChange = (e) => {
const { name, value } = e.target;

setFormData({ ...formData, [name]: value });
};

const handleSubmit = (e) => {
e.preventDefault();

console.log(formData);
const handleCloseSnackbar = () => {
setSnackbarOpen(false);
};

useEffect(() => {
if (_id) {
// If a product ID is available in the URL, fetch product data and pre-fill the form
//if you want to fetch the data with name if Name is Unique then use name also..
axios
.get(`http://localhost:5001/api/video_categories/${_id}`)
.then((response) => {
const videoData = response.data;
setFormData({
title:videoData.title,
// name: productData.name,
// quantity: productData.quantity,
// model: productData.model,
// purchase_price: productData.purchase_price,
// manufacturer: productData.manufacturer,
// sale_price: productData.sale_price,
// date: productData.date,
// available: productData.available,
// description: productData.description,
});
})
.catch((error) => {
console.error('Error fetching product data:', error);
});
}
}, [_id]);

const handleSubmit = (e) => {
e.preventDefault();

if (_id) {
// If _id is defined, it's an edit operation
const apiUrl = `http://localhost:5001/api/video_categories/patch/${_id}`; // Edit
axios
.patch(apiUrl, formData) // Use axios.patch for the PATCH request
.then((response) => {
setSuccessMessage("Product updated successfully!");
setSnackbarOpen(true);
handleReset();
})
.catch((err) => {
console.error(err);
});
} else {
// If _id is not defined, it's an add operation
const apiUrl = "http://localhost:5001/api/video_categories/post"; // Add
axios
.post(apiUrl, formData) // Use axios.post for the POST request
.then((response) => {
setSuccessMessage("Product added successfully!");
setSnackbarOpen(true);
handleReset();
})
.catch((err) => {
console.error(err);
});
}
};


return (
<Box m="1.5rem 2.5rem" ml="350px">
<SidebarAllCategories />
<Box m={isSmallScreen ? "1rem" : "1.5rem 2.5rem"} ml={isSmallScreen ? "10px" : "350px"}>
{/* // m="1.5rem 2.5rem" ml="350px"> */}
{/* <SidebarAllCategories /> */}

<SidebarAllCategories />
{/* <SidebarAllCategories /> */}

<FlexBetween></FlexBetween>

Expand Down Expand Up @@ -140,7 +174,7 @@ const AddCategoryLiveTv = () => {
className="form-control"
placeholder="Image"
id="CategoryFile"
required="required"
// required="required"
></input>
</div>
<br />
Expand All @@ -156,7 +190,7 @@ const AddCategoryLiveTv = () => {
className="form-control"
placeholder="Image"
id="CategoryFile"
required="required"
// required="required"
></input>
</div>
<br />
Expand All @@ -172,7 +206,7 @@ const AddCategoryLiveTv = () => {
className="form-control"
placeholder="Image"
id="CategoryFile"
required="required"
// required="required"
></input>
</div>
<br />
Expand All @@ -188,7 +222,7 @@ const AddCategoryLiveTv = () => {
className="form-control"
placeholder="Image"
id="CategoryFile"
required="required"
// required="required"
></input>
</div>
<br />
Expand All @@ -204,7 +238,7 @@ const AddCategoryLiveTv = () => {
className="form-control"
placeholder="Image"
id="CategoryFile"
required="required"
// required="required"
></input>
</div>
<br />
Expand All @@ -220,15 +254,29 @@ const AddCategoryLiveTv = () => {
className="form-control"
placeholder="Image"
id="CategoryFile"
required="required"
// required="required"
></input>
</div>
<br />
<ButtonGroup variant="contained" aria-label="outlined button group">
<Button>Reset</Button>
<Button>Submit</Button>
<Button type="reset" onClick={handleReset}>Reset</Button>
<Button type="submit">Submit</Button>
</ButtonGroup>
</form>
<Snackbar
open={snackbarOpen}
autoHideDuration={6000} // Adjust the duration as needed
onClose={handleCloseSnackbar}

>
<Alert
onClose={handleCloseSnackbar}
severity="success"
variant="filled"
>
{successMessage}
</Alert>
</Snackbar>
</Box>
);
};
Expand Down
Loading

0 comments on commit 358ebee

Please sign in to comment.