added Toast and modal not close until click on close button

This commit is contained in:
Pramod Mahajan 2025-05-03 01:02:27 +05:30 committed by Vikas Nale
parent fe0b023580
commit 4a77fb82a4
3 changed files with 46 additions and 8 deletions

View File

@ -6,6 +6,7 @@ import ProjectRepository from "../../../repositories/ProjectRepository";
import { useSelector } from "react-redux";
import { useProjectDetails } from "../../../hooks/useProjects";
import {getCachedData} from "../../../slices/apiDataManager";
import showToast from "../../../services/toastService";
// Zod validation schema
const buildingSchema = z.object({
@ -79,10 +80,18 @@ const BuildingModel = ({
const onSubmitHandler = async (data) => {
onSubmit({ ...data, projectId: project.id });
reset({
name: null,
description: null,
});
reset( {
Id:"0",
name: "",
description: "",
} );
if ( data.Id !== "0" )
{
showToast( "Building updated successfully.", "success" );
} else
{
showToast( "Building created successfully.", "success" );
}
};
useEffect( () =>

View File

@ -3,6 +3,7 @@ import { useForm } from "react-hook-form";
import { z } from "zod";
import { zodResolver } from "@hookform/resolvers/zod";
import {getCachedData} from "../../../slices/apiDataManager";
import showToast from "../../../services/toastService";
// Zod validation schema
const floorSchema = z.object({
@ -92,7 +93,7 @@ const FloorModel = ({
buildingId: selectedBuilding.id,
});
setValue("floorName", floor.floorName); // Set floor name for form
setValue("floorName", floor.floorName);
} else {
setFormData({
id: "0",
@ -106,7 +107,19 @@ const FloorModel = ({
// Handle form submission
const onFormSubmit = (data) => {
onSubmit(data);
onSubmit( data );
reset(
{
floorName: ""
} )
if ( data.id !== "0" )
{
showToast( "Floor updated successfully.", "success" );
} else
{
showToast( "Floor created successfully.", "success" );
}
};

View File

@ -2,6 +2,7 @@ import React, { useState, useEffect } from "react";
import { set, useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { z } from "zod";
import showToast from "../../../services/toastService";
// Zod schema for form validation
const workAreaSchema = z.object( {
@ -97,11 +98,25 @@ const WorkAreaModel = ({ project, onSubmit, clearTrigger, onClearComplete, onClo
floorId: data.floorId,
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 = () => {
reset(defaultModel); // Reset the form to initial state
reset(defaultModel);
setSelectedFloor(null);
setSelectedBuilding( null );
onClose()
@ -170,6 +185,7 @@ const WorkAreaModel = ({ project, onSubmit, clearTrigger, onClearComplete, onClo
className="select2 form-select form-select-sm"
{...register("id")}
onChange={handleWorkAreaChange}
>
<option value="0">Create New Work Area</option>
{selectedFloor?.workAreas?.map((workArea) => (