File size: 2,013 Bytes
e3278e4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"use client";

import React, { useState } from "react";
import { Grid, Col, Icon } from "@tremor/react";
import { Title } from "@tremor/react";
import {
    Modal,
    message,
} from "antd";
import { modelDeleteCall } from "./networking";
import { TrashIcon } from "@heroicons/react/outline";

interface DeleteModelProps {
    modelID: string;
    accessToken: string;
}

const DeleteModelButton: React.FC<DeleteModelProps> = ({
    modelID,
    accessToken,
}) => {
    const [isModalVisible, setIsModalVisible] = useState(false);

    const handleDelete = async () => {
        try {
            message.info("Making API Call");
            setIsModalVisible(true);
            const response = await modelDeleteCall(accessToken, modelID);

            console.log("model delete Response:", response);
            message.success(`Model ${modelID} deleted successfully`);
            setIsModalVisible(false);
        } catch (error) {
            console.error("Error deleting the model:", error);
        }
    };

    return (
        <div>
            <Icon
                onClick={() => setIsModalVisible(true)}
                icon={TrashIcon}
                size="sm"
            />

            <Modal
                open={isModalVisible}
                onOk={handleDelete}
                okType="danger"
                onCancel={() => setIsModalVisible(false)}
            >
                <Grid numItems={1} className="gap-2 w-full">

                    <Title>Delete Model</Title>
                    <Col numColSpan={1}>
                        <p>
                            Are you sure you want to delete this model? This action is irreversible.
                        </p>
                    </Col>
                    <Col numColSpan={1}>
                        <p>
                            Model ID: <b>{modelID}</b>
                        </p>
                    </Col>
                </Grid>
            </Modal>
        </div>
    );
};

export default DeleteModelButton;