Skip to content

Commit

Permalink
add categoty api done
Browse files Browse the repository at this point in the history
  • Loading branch information
anwarjunaidkm committed Feb 7, 2023
1 parent 5c41583 commit bcb8a75
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 17 deletions.
41 changes: 30 additions & 11 deletions src/components/dashbords/admin/AddCategory.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,39 @@ import { AddCategoryApi } from '../../../store/admin/AdminSlice';

function AddCategory() {
const dispatch = useDispatch()
const [Input,setInput] =useState()
const [inputValue, setInputValue] = useState("");
const [imageFile, setImageFile] = useState(null);

console.log("add cstegory state=====",Input);


const categoryHandle= (e) =>{
e.preventDefault()
dispatch(AddCategoryApi(Input))
const data = {
inputValue,
imageFile,
};
dispatch(AddCategoryApi(data))
}
const handle =(e)=>{
setInput({
...Input,
[e.target.name] : e.target.value
});

}
const handleInputChange = (e) => {
setInputValue(

e.target.value);
};

const handleImageChange = (e) => {
setImageFile(

e.target.files[0]);
};

// const handle =(e)=>{
// setInput({
// ...Input,
// [e.target.name] : e.target.value
// });

// }



Expand All @@ -49,7 +66,8 @@ function AddCategory() {


}}
onChange={(e)=>handle(e)}
// onChange={(e)=>handle(e)}
onChange={handleInputChange}
/>
<input
type="file"
Expand All @@ -64,7 +82,8 @@ function AddCategory() {
margin: "8px",
name:"image"
}}
onChange={(e)=>handle(e)}
// onChange={(e)=>handle(e)}
onChange={handleImageChange}

/>
{/* <select style={{
Expand Down
1 change: 1 addition & 0 deletions src/components/login/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ function Login() {
<div className="login-right">
<div>
<form onSubmit={handleLogin}>


<h4 style={{color:"#6a3921"}}>Login</h4>
<p style={{color:"gray",fontSize:"10px"}}>Lorem, ipsum dolor ipsum dolor ipsum !!</p>
Expand Down
18 changes: 14 additions & 4 deletions src/store/admin/AdminSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,18 @@ export const AllevenTeamApi =createAsyncThunk(
//-<<-----------add category------------------------->>
export const AddCategoryApi = createAsyncThunk(
"admin/AddCategoryApi",
async(data)=>{
console.log("DATA==",data);
const res = await axiosApi.post("/store/subcatagory/",data)
console.log("add category==",res);
async({inputValue,imageFile})=>{


const formData = new FormData();
formData.append("sub_catagory_name", inputValue);
formData.append("image", imageFile);
const res = await axiosApi.post("/store/subcatagory/", formData, {
headers: {
"Content-Type": "multipart/form-data"
}
});

return res

}
Expand All @@ -39,6 +47,7 @@ const INITIAL_STATE ={
loading:false,
allusersList:[],
alleventtTeam:[],




Expand Down Expand Up @@ -86,6 +95,7 @@ const AdminSlice =createSlice({
[AddCategoryApi.fulfilled]:(state,action)=>{
state.loading=false
console.log("success");

},
[AddCategoryApi.rejected]:(state,action)=>{
console.log("faild");
Expand Down
4 changes: 2 additions & 2 deletions src/store/auth/AuthSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ import axiosApi from "../AxiosInstance";
const res=axiosApi.post("/auth/token/logout/")
console.log(res);
if (res?.data) {
localStorage.clear();
sessionStorage.clear();
// localStorage.clear();
// sessionStorage.clear();
navigate("/");
}

Expand Down

0 comments on commit bcb8a75

Please sign in to comment.