fixed modals to clear after adding users / tasks / availabilities / events
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
# TODO
|
# TODO
|
||||||
|
|
||||||
- readme text
|
- readme text
|
||||||
- add user/ event / etc. boxes don't clear after adding
|
|
||||||
- check enter pressing on modals
|
- check enter pressing on modals
|
||||||
- add control-enter on event-description
|
- add control-enter on event-description
|
||||||
|
|||||||
@@ -2,23 +2,30 @@ import { apiCall } from "@/lib";
|
|||||||
import AvailabilityEditor, { Availability } from "./AvailabilityEditor";
|
import AvailabilityEditor, { Availability } from "./AvailabilityEditor";
|
||||||
import { Button } from "@heroui/react";
|
import { Button } from "@heroui/react";
|
||||||
import { AddLarge } from "@carbon/icons-react";
|
import { AddLarge } from "@carbon/icons-react";
|
||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
export default function AddAvailability(props: {
|
export default function AddAvailability(props: {
|
||||||
isOpen?: boolean;
|
isOpen?: boolean;
|
||||||
onOpenChange?: (isOpen: boolean) => void;
|
onOpenChange?: (isOpen: boolean) => void;
|
||||||
onSuccess?: () => void;
|
onSuccess?: () => void;
|
||||||
}) {
|
}) {
|
||||||
|
const [addAvailabilityKey, setAddAvailabilityKey] = useState<number>(0);
|
||||||
|
|
||||||
async function addAvailability(a: Availability) {
|
async function addAvailability(a: Availability) {
|
||||||
const result = await apiCall("POST", "availabilities", undefined, a);
|
const result = await apiCall("POST", "availabilities", undefined, a);
|
||||||
|
|
||||||
if (result.ok) {
|
if (result.ok) {
|
||||||
props.onSuccess?.();
|
|
||||||
props.onOpenChange?.(false);
|
props.onOpenChange?.(false);
|
||||||
|
|
||||||
|
setAddAvailabilityKey(addAvailabilityKey + 1);
|
||||||
|
|
||||||
|
props.onSuccess?.();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AvailabilityEditor
|
<AvailabilityEditor
|
||||||
|
key={addAvailabilityKey}
|
||||||
header="Add Availability"
|
header="Add Availability"
|
||||||
footer={
|
footer={
|
||||||
<Button type="submit" color="primary" startContent={<AddLarge />}>
|
<Button type="submit" color="primary" startContent={<AddLarge />}>
|
||||||
|
|||||||
@@ -2,23 +2,30 @@ import { apiCall, Task } from "@/lib";
|
|||||||
import TaskEditor from "./TaskEditor";
|
import TaskEditor from "./TaskEditor";
|
||||||
import { Button } from "@heroui/react";
|
import { Button } from "@heroui/react";
|
||||||
import { AddLarge } from "@carbon/icons-react";
|
import { AddLarge } from "@carbon/icons-react";
|
||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
export default function AddTask(props: {
|
export default function AddTask(props: {
|
||||||
isOpen?: boolean;
|
isOpen?: boolean;
|
||||||
onOpenChange?: (isOpen: boolean) => void;
|
onOpenChange?: (isOpen: boolean) => void;
|
||||||
onSuccess?: () => void;
|
onSuccess?: () => void;
|
||||||
}) {
|
}) {
|
||||||
|
const [addTaskKey, setAddTaskKey] = useState<number>(0);
|
||||||
|
|
||||||
async function addTask(a: Task) {
|
async function addTask(a: Task) {
|
||||||
const result = await apiCall("POST", "tasks", undefined, a);
|
const result = await apiCall("POST", "tasks", undefined, a);
|
||||||
|
|
||||||
if (result.ok) {
|
if (result.ok) {
|
||||||
props.onSuccess?.();
|
|
||||||
props.onOpenChange?.(false);
|
props.onOpenChange?.(false);
|
||||||
|
|
||||||
|
setAddTaskKey(addTaskKey);
|
||||||
|
|
||||||
|
props.onSuccess?.();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TaskEditor
|
<TaskEditor
|
||||||
|
key={addTaskKey}
|
||||||
header="Add Task"
|
header="Add Task"
|
||||||
footer={
|
footer={
|
||||||
<Button type="submit" color="primary" startContent={<AddLarge />}>
|
<Button type="submit" color="primary" startContent={<AddLarge />}>
|
||||||
|
|||||||
@@ -3,23 +3,28 @@ import { AddLarge } from "@carbon/icons-react";
|
|||||||
import { Button } from "@heroui/react";
|
import { Button } from "@heroui/react";
|
||||||
import UserEditor from "./UserEditor";
|
import UserEditor from "./UserEditor";
|
||||||
import { UserAddModify } from "@/Zustand";
|
import { UserAddModify } from "@/Zustand";
|
||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
export default function AddUser(props: {
|
export default function AddUser(props: {
|
||||||
isOpen?: boolean;
|
isOpen?: boolean;
|
||||||
onOpenChange?: (isOpen: boolean) => void;
|
onOpenChange?: (isOpen: boolean) => void;
|
||||||
onSuccess?: () => void;
|
onSuccess?: () => void;
|
||||||
}) {
|
}) {
|
||||||
|
const [addUserKey, setAddUserKey] = useState<number>(0);
|
||||||
|
|
||||||
// send an addUser request to the backend then reload the table
|
// send an addUser request to the backend then reload the table
|
||||||
async function sendAddUser(user: UserAddModify) {
|
async function sendAddUser(user: UserAddModify) {
|
||||||
const result = await apiCall("POST", "users", undefined, user);
|
const result = await apiCall("POST", "users", undefined, user);
|
||||||
|
|
||||||
if (result.ok) {
|
if (result.ok) {
|
||||||
|
setAddUserKey(addUserKey + 1);
|
||||||
props.onSuccess?.();
|
props.onSuccess?.();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<UserEditor
|
<UserEditor
|
||||||
|
key={addUserKey}
|
||||||
isPasswordRequired
|
isPasswordRequired
|
||||||
isOpen={props.isOpen}
|
isOpen={props.isOpen}
|
||||||
onOpenChange={props.onOpenChange}
|
onOpenChange={props.onOpenChange}
|
||||||
|
|||||||
@@ -101,7 +101,9 @@ export default function UserEditor(props: {
|
|||||||
<Input
|
<Input
|
||||||
isRequired={props.isPasswordRequired}
|
isRequired={props.isPasswordRequired}
|
||||||
label="Password"
|
label="Password"
|
||||||
color={password.length > 0 ? "warning" : "default"}
|
color={
|
||||||
|
password.length > 0 && !!props.value ? "warning" : "default"
|
||||||
|
}
|
||||||
name="password"
|
name="password"
|
||||||
variant="bordered"
|
variant="bordered"
|
||||||
value={password}
|
value={password}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { Button } from "@heroui/react";
|
|||||||
import { apiCall } from "@/lib";
|
import { apiCall } from "@/lib";
|
||||||
import { AddLarge } from "@carbon/icons-react";
|
import { AddLarge } from "@carbon/icons-react";
|
||||||
import EventEditor, { EventSubmitData } from "./EventEditor";
|
import EventEditor, { EventSubmitData } from "./EventEditor";
|
||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
export default function AddEvent(props: {
|
export default function AddEvent(props: {
|
||||||
className?: string;
|
className?: string;
|
||||||
@@ -9,18 +10,23 @@ export default function AddEvent(props: {
|
|||||||
onOpenChange: (isOpen: boolean) => void;
|
onOpenChange: (isOpen: boolean) => void;
|
||||||
onSuccess?: () => void;
|
onSuccess?: () => void;
|
||||||
}) {
|
}) {
|
||||||
|
const [addEventKey, setAddEventKey] = useState<number>(0);
|
||||||
|
|
||||||
async function addEvent(data: EventSubmitData) {
|
async function addEvent(data: EventSubmitData) {
|
||||||
const result = await apiCall("POST", "events", undefined, data);
|
const result = await apiCall("POST", "events", undefined, data);
|
||||||
|
|
||||||
if (result.ok) {
|
if (result.ok) {
|
||||||
props.onOpenChange(false);
|
props.onOpenChange(false);
|
||||||
|
|
||||||
|
setAddEventKey(addEventKey + 1);
|
||||||
|
|
||||||
props.onSuccess?.();
|
props.onSuccess?.();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<EventEditor
|
<EventEditor
|
||||||
|
key={addEventKey}
|
||||||
{...props}
|
{...props}
|
||||||
header="Add Event"
|
header="Add Event"
|
||||||
onSubmit={(data) => void addEvent(data)}
|
onSubmit={(data) => void addEvent(data)}
|
||||||
|
|||||||
Reference in New Issue
Block a user