added Toast and modal not close until click on close button
This commit is contained in:
parent
fe0b023580
commit
4a77fb82a4
@ -6,6 +6,7 @@ import ProjectRepository from "../../../repositories/ProjectRepository";
|
|||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
import { useProjectDetails } from "../../../hooks/useProjects";
|
import { useProjectDetails } from "../../../hooks/useProjects";
|
||||||
import {getCachedData} from "../../../slices/apiDataManager";
|
import {getCachedData} from "../../../slices/apiDataManager";
|
||||||
|
import showToast from "../../../services/toastService";
|
||||||
|
|
||||||
// Zod validation schema
|
// Zod validation schema
|
||||||
const buildingSchema = z.object({
|
const buildingSchema = z.object({
|
||||||
@ -79,10 +80,18 @@ const BuildingModel = ({
|
|||||||
|
|
||||||
const onSubmitHandler = async (data) => {
|
const onSubmitHandler = async (data) => {
|
||||||
onSubmit({ ...data, projectId: project.id });
|
onSubmit({ ...data, projectId: project.id });
|
||||||
reset({
|
reset( {
|
||||||
name: null,
|
Id:"0",
|
||||||
description: null,
|
name: "",
|
||||||
});
|
description: "",
|
||||||
|
} );
|
||||||
|
if ( data.Id !== "0" )
|
||||||
|
{
|
||||||
|
showToast( "Building updated successfully.", "success" );
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
showToast( "Building created successfully.", "success" );
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect( () =>
|
useEffect( () =>
|
||||||
|
@ -3,6 +3,7 @@ import { useForm } from "react-hook-form";
|
|||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import {getCachedData} from "../../../slices/apiDataManager";
|
import {getCachedData} from "../../../slices/apiDataManager";
|
||||||
|
import showToast from "../../../services/toastService";
|
||||||
|
|
||||||
// Zod validation schema
|
// Zod validation schema
|
||||||
const floorSchema = z.object({
|
const floorSchema = z.object({
|
||||||
@ -92,7 +93,7 @@ const FloorModel = ({
|
|||||||
buildingId: selectedBuilding.id,
|
buildingId: selectedBuilding.id,
|
||||||
|
|
||||||
});
|
});
|
||||||
setValue("floorName", floor.floorName); // Set floor name for form
|
setValue("floorName", floor.floorName);
|
||||||
} else {
|
} else {
|
||||||
setFormData({
|
setFormData({
|
||||||
id: "0",
|
id: "0",
|
||||||
@ -106,7 +107,19 @@ const FloorModel = ({
|
|||||||
|
|
||||||
// Handle form submission
|
// Handle form submission
|
||||||
const onFormSubmit = (data) => {
|
const onFormSubmit = (data) => {
|
||||||
onSubmit(data);
|
onSubmit( data );
|
||||||
|
reset(
|
||||||
|
{
|
||||||
|
floorName: ""
|
||||||
|
} )
|
||||||
|
if ( data.id !== "0" )
|
||||||
|
{
|
||||||
|
showToast( "Floor updated successfully.", "success" );
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
showToast( "Floor created successfully.", "success" );
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ import React, { useState, useEffect } from "react";
|
|||||||
import { set, useForm } from "react-hook-form";
|
import { set, useForm } from "react-hook-form";
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
import showToast from "../../../services/toastService";
|
||||||
|
|
||||||
// Zod schema for form validation
|
// Zod schema for form validation
|
||||||
const workAreaSchema = z.object( {
|
const workAreaSchema = z.object( {
|
||||||
@ -97,11 +98,25 @@ const WorkAreaModel = ({ project, onSubmit, clearTrigger, onClearComplete, onClo
|
|||||||
floorId: data.floorId,
|
floorId: data.floorId,
|
||||||
buildingId:data.buildingId
|
buildingId:data.buildingId
|
||||||
}
|
}
|
||||||
onSubmit(WorkArea); // Send the final data to the parent
|
onSubmit( WorkArea );
|
||||||
|
|
||||||
|
reset( {
|
||||||
|
id:"0",
|
||||||
|
areaName:""
|
||||||
|
} );
|
||||||
|
if ( data.id !== "0" )
|
||||||
|
{
|
||||||
|
showToast( "WorkArea updated successfully.", "success" );
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
showToast( "WorkArea created successfully.", "success" );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleCancel = () => {
|
const handleCancel = () => {
|
||||||
reset(defaultModel); // Reset the form to initial state
|
reset(defaultModel);
|
||||||
setSelectedFloor(null);
|
setSelectedFloor(null);
|
||||||
setSelectedBuilding( null );
|
setSelectedBuilding( null );
|
||||||
onClose()
|
onClose()
|
||||||
@ -170,6 +185,7 @@ const WorkAreaModel = ({ project, onSubmit, clearTrigger, onClearComplete, onClo
|
|||||||
className="select2 form-select form-select-sm"
|
className="select2 form-select form-select-sm"
|
||||||
{...register("id")}
|
{...register("id")}
|
||||||
onChange={handleWorkAreaChange}
|
onChange={handleWorkAreaChange}
|
||||||
|
|
||||||
>
|
>
|
||||||
<option value="0">Create New Work Area</option>
|
<option value="0">Create New Work Area</option>
|
||||||
{selectedFloor?.workAreas?.map((workArea) => (
|
{selectedFloor?.workAreas?.map((workArea) => (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user