Skip to content

Commit

Permalink
inventory updated
Browse files Browse the repository at this point in the history
  • Loading branch information
rupomsoft committed Oct 5, 2022
1 parent 43c6d05 commit 5f6d32c
Show file tree
Hide file tree
Showing 19 changed files with 159 additions and 40 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file modified Inventory/.DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const CreateParentChildsService= async (Request, ParentModel, ChildsModel,JoinPr
// Roll Back Transaction if Fail
await session.abortTransaction();
session.endSession();
return {status: "fail", data: error.toString()}
return {status: "fail", data: error}
}
}
module.exports=CreateParentChildsService
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const CreateService= async (Request,DataModel) => {
return {status: "success", data: data}
}
catch (error) {
return {status: "fail", data: error.toString()}
return {status: "fail", data: error}
}
}
module.exports=CreateService
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const DeleteParentChildsService= async (Request, ParentModel,ChildsModel,JoinPro
// Roll Back Transaction
await session.abortTransaction();
session.endSession();
return {status: "fail", data: error.toString()}
return {status: "fail", data: error}
}
}
module.exports=DeleteParentChildsService
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const DeleteService= async (Request, Model) => {

}
catch (error) {
return {status: "fail", data: error.toString()}
return {status: "fail", data: error}
}
}
module.exports=DeleteService
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const DetailsByIDService= async (Request,DataModel) => {
return {status: "success", data: data}
}
catch (error) {
return {status: "fail", data: error.toString()}
return {status: "fail", data: error}
}
}
module.exports=DetailsByIDService
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const DropDownService= async (Request,DataModel,Projection) => {
return {status: "success", data: data}
}
catch (error) {
return {status: "fail", data: error.toString()}
return {status: "fail", data: error}
}
}
module.exports=DropDownService
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const ListOneJoinService= async (Request, DataModel, SearchArray, JoinStage) =>
return {status: "success", data: data}
}
catch (error) {
return {status: "fail", data: error.toString()}
return {status: "fail", data: error}
}
}
module.exports=ListOneJoinService
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const ListService= async (Request,DataModel,SearchArray) => {
return {status: "success", data: data}
}
catch (error) {
return {status: "fail", data: error.toString()}
return {status: "fail", data: error}
}
}
module.exports=ListService
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const ListTwoJoinService= async (Request, DataModel, SearchArray, JoinStage1,Joi
return {status: "success", data: data}
}
catch (error) {
return {status: "fail", data: error.toString()}
return {status: "fail", data: error}
}
}
module.exports=ListTwoJoinService
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const UpdateService= async (Request,DataModel) => {
return {status: "success", data: data}
}
catch (error) {
return {status: "fail", data: error.toString()}
return {status: "fail", data: error}
}
}
module.exports=UpdateService
Expand Down
10 changes: 10 additions & 0 deletions Inventory/inventory-mern-frontend/.idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import {HideLoader, ShowLoader} from "../redux/state-slice/settings-slice";
import axios from "axios";
import {ErrorToast, SuccessToast} from "../helper/FormHelper";
import {getToken} from "../helper/SessionHelper";
import {SetCustomerList, SetCustomerListTotal} from "../redux/state-slice/customer-slice";
import {
OnChangeCustomerInput,
ResetFormValue,
SetCustomerList,
SetCustomerListTotal
} from "../redux/state-slice/customer-slice";
import {BaseURL} from "../helper/config";
const AxiosHeader={headers:{"token":getToken()}}

Expand Down Expand Up @@ -33,18 +38,90 @@ export async function CustomerListRequest(pageNo, perPage, searchKeyword) {
}




export async function CreateCustomerRequest(PostBody) {
export async function CreateCustomerRequest(PostBody,ObjectID) {
try {
store.dispatch(ShowLoader())
let URL = BaseURL+"/CreateCustomers"
if(ObjectID!==0){
URL = BaseURL+"/UpdateCustomers/"+ObjectID;
}
const result = await axios.post(URL,PostBody,AxiosHeader)
store.dispatch(HideLoader())
if (result.status === 200 && result.data['status'] === "success") {
SuccessToast("Request Successful");
store.dispatch(ResetFormValue())
return true;

}
else if(result.status === 200 && result.data['status'] === "fail") {
if(result.data['data']['keyPattern']['Phone']===1){
ErrorToast("Mobile Number Already Exist")
return false;
}
}
else {
ErrorToast("Request Fail ! Try Again")
return false;
}
}
catch (e) {
ErrorToast("Something Went Wrong")
store.dispatch(HideLoader())
return false
}
}


export async function FillCustomerFormRequest(ObjectID) {
try {
store.dispatch(ShowLoader())
let URL = BaseURL+"/CustomersDetailsByID/"+ObjectID;
const result = await axios.get(URL,AxiosHeader)
store.dispatch(HideLoader())
if (result.status === 200 && result.data['status'] === "success") {

let FormValue=result.data['data'][0];

store.dispatch(OnChangeCustomerInput({Name:"CustomerName",Value:FormValue['CustomerName']}));
store.dispatch(OnChangeCustomerInput({Name:"Phone",Value:FormValue['Phone']}));
store.dispatch(OnChangeCustomerInput({Name:"Email",Value:FormValue['Email']}));
store.dispatch(OnChangeCustomerInput({Name:"Address",Value:FormValue['Address']}));

debugger;


return true;
} else {
debugger;
ErrorToast("Request Fail ! Try Again")
return false;
}
}
catch (e) {
debugger;
ErrorToast("Something Went Wrong")
store.dispatch(HideLoader())
return false
}
}



export async function DeleteCustomerRequest(ObjectID) {
try {
store.dispatch(ShowLoader())
let URL = BaseURL+"/DeleteCustomer/"+ObjectID;
const result = await axios.get(URL,AxiosHeader)
store.dispatch(HideLoader())
if (result.status === 200 && result.data['status'] === "associate") {
ErrorToast(result.data['data'])
return false;
}
if (result.status === 200 && result.data['status'] === "success") {
SuccessToast("Request Successful");
return true
}
else {
ErrorToast("Request Fail ! Try Again")
return false;
}
Expand All @@ -59,3 +136,8 @@ export async function CreateCustomerRequest(PostBody) {








Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
import React, {Fragment} from 'react';
import React, {Fragment, useEffect, useState} from 'react';
import {useSelector} from "react-redux";
import store from "../../redux/store/store";
import {OnChangeCustomerInput} from "../../redux/state-slice/customer-slice";
import {CreateCustomerRequest} from "../../APIRequest/CustomerAPIRequest";
import {CreateCustomerRequest, FillCustomerFormRequest} from "../../APIRequest/CustomerAPIRequest";
import {ErrorToast, IsEmail, IsEmpty} from "../../helper/FormHelper";
import {useNavigate} from "react-router-dom";
const CustomerCreateUpdate = () => {

let FormValue=useSelector((state)=>(state.customer.FormValue));
let navigate=useNavigate();
let [ObjectID,SetObjectID]=useState(0);

useEffect(()=>{
let params= new URLSearchParams(window.location.search);
let id=params.get('id');
if(id!==null){
SetObjectID(id);
(async () => {
await FillCustomerFormRequest(id);
})();
}
},[])



const SaveChange = async () => {
if(IsEmpty(FormValue.CustomerName)){
Expand All @@ -21,7 +35,7 @@ const CustomerCreateUpdate = () => {
ErrorToast("Valid Email Address Required !")
}
else {
if(await CreateCustomerRequest(FormValue)){
if(await CreateCustomerRequest(FormValue,ObjectID)){
navigate("/CustomerListPage")
}
}
Expand All @@ -38,6 +52,7 @@ const CustomerCreateUpdate = () => {
<div className="row">
<h5 >Save Customer</h5>
<hr className="bg-light"/>

<div className="col-4 p-2">
<label className="form-label">Customer Name</label>
<input onChange={(e)=>{store.dispatch(OnChangeCustomerInput({Name:"CustomerName",Value:e.target.value}))}} value={FormValue.CustomerName} className="form-control form-control-sm" type="text"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React, {Fragment, useEffect, useState} from 'react';
import {CustomerListRequest} from "../../APIRequest/CustomerAPIRequest";
import {CustomerListRequest, DeleteCustomerRequest} from "../../APIRequest/CustomerAPIRequest";
import {useSelector} from "react-redux";
import {Link} from "react-router-dom";
import {AiOutlineEdit, AiOutlineEye} from "react-icons/all";
import {AiOutlineDelete, AiOutlineEdit} from "react-icons/all";
import ReactPaginate from "react-paginate";
import moment from "moment/moment";
import Swal from "sweetalert2";
import {DeleteAlert} from "../../helper/DeleteAlert";


const CustomerList = () => {
let [searchKeyword,setSearchKeyword]=useState("0");
Expand Down Expand Up @@ -44,21 +44,15 @@ const CustomerList = () => {
row.style.display = (row.innerText.includes(e.target.value)) ? '' : 'none'
})
}
const DetailsPopUp = (item) => {
Swal.fire({
html:`
<ul class="list-group text-start list-group-flush">
<li class="list-group-item"><span class="text-xs text-start"><b>Name :</b> ${item.CustomerName}</span></li>
<li class="list-group-item"><span class="text-xs text-start"><b>Phone :</b> ${item.Phone} </span></li>
<li class="list-group-item"><span class="text-xs text-start"><b>Email :</b> ${item.Email}</span></li>
<li class="list-group-item"><span class="text-xs text-start"><b>Address: </b> ${item.Address}</span></li>
<li class="list-group-item"><span class="text-xs text-start"><b>Created Date</b> ${moment(item.CreatedDate).format('MMMM Do YYYY')}</span></li>
</ul>
`,
showCloseButton: true,
showConfirmButton: false,
focusCancel: false,
})

const DeleteItem = async (id) => {
let Result = await DeleteAlert();
if(Result.isConfirmed){
let DeleteResult= await DeleteCustomerRequest(id)
if(DeleteResult){
await CustomerListRequest(1,perPage,searchKeyword);
}
}
}

return (
Expand Down Expand Up @@ -120,8 +114,8 @@ const CustomerList = () => {
<Link to={`/CustomerCreateUpdatePage?id=${item._id}`} className="btn text-info btn-outline-light p-2 mb-0 btn-sm">
<AiOutlineEdit size={15} />
</Link>
<button onClick={DetailsPopUp.bind(this,item)} className="btn btn-outline-light text-success p-2 mb-0 btn-sm ms-2">
<AiOutlineEye size={15} />
<button onClick={DeleteItem.bind(this,item._id)} className="btn btn-outline-light text-danger p-2 mb-0 btn-sm ms-2">
<AiOutlineDelete size={15} />
</button>
</td>
</tr>
Expand Down
16 changes: 16 additions & 0 deletions Inventory/inventory-mern-frontend/src/helper/DeleteAlert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import Swal from "sweetalert2";


export async function DeleteAlert() {
return await Swal.fire({
allowOutsideClick: false,
title: 'Are you sure?',
text: "You won't be able to revert this!",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!'
});

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ export const customerSlice=createSlice({
},
OnChangeCustomerInput:(state,action)=>{
state.FormValue[`${action.payload.Name}`]=action.payload.Value;
},
ResetFormValue:(state,action)=>{
Object.keys(state.FormValue).forEach((i) => state.FormValue[i] = "");
}


}
})

export const {SetCustomerList,SetCustomerListTotal,OnChangeCustomerInput}=customerSlice.actions;
export const {SetCustomerList,SetCustomerListTotal,OnChangeCustomerInput,ResetFormValue}=customerSlice.actions;
export default customerSlice.reducer;
Binary file modified Task-Manager-Project/.DS_Store
Binary file not shown.

0 comments on commit 5f6d32c

Please sign in to comment.