Untitled

 avatar
user_6104052
javascript
5 months ago
2.6 kB
2
Indexable
import React, { useState } from 'react';
import Loader from "../../../../control-components/loader/loader";
import { Dialog, DialogActionsBar } from '@progress/kendo-react-dialogs';
import NotificationManager from 'react-notifications/lib/NotificationManager';
import { ClientService } from '../../../../services/clientService';
import NOTIFICATION_MESSAGE from '../../../../helper/notification-messages';
import { useSelector } from "react-redux";
import { renderErrors } from "src/helper/error-message-helper";


const DeleteSignature = ({ onClose, clientSignObj, staffSignObj, setIsGoalRefreshed }) => {
    const [loading, setLoading] = useState(false);
    const staffId = useSelector(state => state.loggedIn?.staffId);
    const selectedClientId = useSelector(state => state.selectedClientId);

    const deleteClientSign = async () => {
        setLoading(true)
        await ClientService.deleteClientPlanSignature(selectedClientId, clientSignObj)
            .then(result => {
                setLoading(false)
                NotificationManager.success(NOTIFICATION_MESSAGE.SIGNATURE_DELETED)
                onClose({ "isDeleted": true });
                setIsGoalRefreshed(true)
            }).catch(error => {
                renderErrors(error)
                setLoading(false)
            });
    }

    const deleteStaffSign = async () => {
        setLoading(true)
        await ClientService.deleteStaffPlanSignature(staffSignObj.id, staffSignObj.staffId)
            .then(result => {
                setLoading(false)
                NotificationManager.success(NOTIFICATION_MESSAGE.SIGNATURE_DELETED)
                onClose({ "isDeleted": true });
                setIsGoalRefreshed(true)
            }).catch(error => {
                renderErrors(error)
                setLoading(false)
            });
    }

    const handleDelete = () => {
        if (staffSignObj.staffId) {
            deleteStaffSign()
        } else {
            deleteClientSign()
        }
    }

    return (
        <Dialog onClose={onClose} title={"Delete Signature "} className='xs-modal blue_theme'>
            {loading === true && <Loader />}
            <p style={{
                margin: "25px",
            }}> Are you sure you want to delete ? </p>
            <DialogActionsBar>
            <button className="cancelBtn px-4" onClick={onClose} >No</button>
            <button className="submitButon px-4" onClick={handleDelete} >Yes</button>
                
            </DialogActionsBar>
        </Dialog>
    );
}
export default DeleteSignature;



Leave a Comment