-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathCheckModal.tsx
More file actions
104 lines (100 loc) · 3.13 KB
/
CheckModal.tsx
File metadata and controls
104 lines (100 loc) · 3.13 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import { createStore } from "solid-js/store";
import type { CreateCheckRequest } from "@/types";
type CheckValues = {
name: string;
module: string;
description: string;
};
const EditCheckModal = ({
modalAction,
closeModal,
}: {
modalAction: (check: CreateCheckRequest) => Promise<void>;
closeModal: () => void;
}) => {
const [newCheck, setNewCheck] = createStore<CheckValues>({
name: "",
module: "",
description: "",
});
// Styling for the Add button based on whether fields are filled
const isAddDisabled = () => {
return (
newCheck.name.trim() === "" ||
newCheck.description.trim() === "" ||
newCheck.module.trim() === ""
);
};
const addButtonClasses = () => {
return isAddDisabled()
? "opacity-50 cursor-not-allowed"
: "hover:bg-sky-700";
};
return (
<div class="fixed inset-0 bg-black/40 flex items-center justify-center z-50">
<div class="bg-white px-12 py-8 rounded-xl max-w-140 w-1/2 min-w-80 min-h-96">
<div class="text-2xl font-bold mb-4">Create New Check</div>
<div class="mb-4">
<label class="block font-bold mb-2">Name:</label>
<input
type="text"
class="form-input w-full border border-gray-300 rounded px-3 py-2"
value={newCheck.name}
onInput={(e) => setNewCheck("name", e.currentTarget.value)}
placeholder="Enter check name"
/>
</div>
<div class="mb-4">
<label class="block font-bold mb-2">Module:</label>
<input
type="text"
class="form-input w-full border border-gray-300 rounded px-3 py-2"
value={newCheck.module}
onInput={(e) => setNewCheck("module", e.currentTarget.value)}
placeholder="Enter check module"
/>
</div>
<div class="mb-4">
<label class="block font-bold mb-2">Description:</label>
<textarea
class="w-full border border-gray-300 rounded px-3 py-2"
value={newCheck.description}
onInput={(e) => setNewCheck("description", e.currentTarget.value)}
placeholder="Enter check description"
rows={4}
/>
</div>
<div class="flex justify-end space-x-2">
<div
class="btn-default hover:bg-gray-200"
onClick={() => {
closeModal();
}}
>
Cancel
</div>
<div
class={"btn-default bg-sky-600 text-white " + addButtonClasses()}
onClick={async () => {
if (isAddDisabled()) {
console.log("Please fill in all fields.");
return;
}
const check: CreateCheckRequest = {
name: newCheck.name,
module: newCheck.module,
description: newCheck.description,
parameterDefinitions: [],
};
await modalAction(check);
closeModal();
}}
>
Add Check
</div>
</div>
</div>
</div>
);
};
export default EditCheckModal;