mirror of
https://github.com/crocofied/CoreControl.git
synced 2025-12-29 16:14:43 +00:00
Add site functionallity
This commit is contained in:
@@ -1,5 +1,36 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useState } from "react";
|
||||||
|
import axios from "axios";
|
||||||
|
import ErrorToast from "@/components/Error";
|
||||||
|
import SuccessToast from "@/components/Success";
|
||||||
|
|
||||||
export default function AddSite() {
|
export default function AddSite() {
|
||||||
|
const [name, setName] = useState("");
|
||||||
|
const [description, setDescription] = useState("");
|
||||||
|
const [error, setError] = useState("");
|
||||||
|
const [success, setSuccess] = useState("");
|
||||||
|
|
||||||
|
const addSite = async () => {
|
||||||
|
try {
|
||||||
|
const response = await axios.post("/api/sites/add", { name, description });
|
||||||
|
if (response.status === 201) {
|
||||||
|
const site = response.data.site;
|
||||||
|
if (site) {
|
||||||
|
setName("");
|
||||||
|
setDescription("");
|
||||||
|
setSuccess("Site added successfully");
|
||||||
|
} else {
|
||||||
|
setError("No site received");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
setError(error.response.data.error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<div>
|
||||||
<dialog id="add_site" className="modal">
|
<dialog id="add_site" className="modal">
|
||||||
<div className="modal-box w-2/3 max-w-2/3">
|
<div className="modal-box w-2/3 max-w-2/3">
|
||||||
<div className="flex flex-col gap-4">
|
<div className="flex flex-col gap-4">
|
||||||
@@ -17,6 +48,8 @@ export default function AddSite() {
|
|||||||
type="text"
|
type="text"
|
||||||
className="input input-bordered w-full focus:ring-2"
|
className="input input-bordered w-full focus:ring-2"
|
||||||
placeholder="e.g. Downtown Office"
|
placeholder="e.g. Downtown Office"
|
||||||
|
value={name}
|
||||||
|
onChange={(e) => setName(e.target.value)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -31,6 +64,8 @@ export default function AddSite() {
|
|||||||
className="textarea textarea-bordered w-full focus:ring-2"
|
className="textarea textarea-bordered w-full focus:ring-2"
|
||||||
placeholder="Enter a brief description..."
|
placeholder="Enter a brief description..."
|
||||||
rows={4}
|
rows={4}
|
||||||
|
value={description}
|
||||||
|
onChange={(e) => setDescription(e.target.value)}
|
||||||
></textarea>
|
></textarea>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -38,11 +73,14 @@ export default function AddSite() {
|
|||||||
<div className="modal-action flex justify-end">
|
<div className="modal-action flex justify-end">
|
||||||
<form method="dialog" className="flex gap-3">
|
<form method="dialog" className="flex gap-3">
|
||||||
<button className="btn btn-ghost">Cancel</button>
|
<button className="btn btn-ghost">Cancel</button>
|
||||||
<button className="btn btn-primary px-6">Add Site</button>
|
<button className="btn btn-primary px-6" onClick={addSite}>Add Site</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</dialog>
|
</dialog>
|
||||||
|
<ErrorToast message={error} show={error !== ''} onClose={() => setError('')} />
|
||||||
|
<SuccessToast message={success} show={success !== ''} onClose={() => setSuccess('')} />
|
||||||
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user