adding title error
This commit is contained in:
parent
0a13f67915
commit
c3f0cb921c
@ -44,7 +44,7 @@ export default function CreateCalendarEventModal() {
|
|||||||
imageUrl,
|
imageUrl,
|
||||||
status: imageStatus,
|
status: imageStatus,
|
||||||
} = useImageUpload("event");
|
} = useImageUpload("event");
|
||||||
const [error, setError] = useState("");
|
const [error, setError] = useState<Record<string, string | undefined>>({});
|
||||||
const [title, setTitle] = useState("");
|
const [title, setTitle] = useState("");
|
||||||
const [description, setDescription] = useState("");
|
const [description, setDescription] = useState("");
|
||||||
const [startDate, setStartDate] = useState<Date>(now);
|
const [startDate, setStartDate] = useState<Date>(now);
|
||||||
@ -81,17 +81,27 @@ export default function CreateCalendarEventModal() {
|
|||||||
const { currentUser, calendars } = useCurrentUser();
|
const { currentUser, calendars } = useCurrentUser();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (error["title"]) {
|
||||||
|
if (title) {
|
||||||
|
setError((prev) => ({ ...prev, title: undefined }));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [title, error]);
|
||||||
|
|
||||||
async function handleSubmit() {
|
async function handleSubmit() {
|
||||||
if (!ndk || !currentUser) {
|
if (!ndk || !currentUser) {
|
||||||
alert("MISSING");
|
alert("MISSING");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setIsLoading(true);
|
|
||||||
if (!title) {
|
if (!title) {
|
||||||
setError("Please add a title");
|
setError({
|
||||||
|
title: "Please add a title",
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
setIsLoading(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const random = randomId();
|
const random = randomId();
|
||||||
@ -169,8 +179,6 @@ export default function CreateCalendarEventModal() {
|
|||||||
const titleRef = useRef<HTMLTextAreaElement>(null);
|
const titleRef = useRef<HTMLTextAreaElement>(null);
|
||||||
useAutosizeTextArea(titleRef.current, title);
|
useAutosizeTextArea(titleRef.current, title);
|
||||||
|
|
||||||
console.log(Intl.DateTimeFormat().resolvedOptions().timeZone);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={cn(
|
className={cn(
|
||||||
@ -193,6 +201,8 @@ export default function CreateCalendarEventModal() {
|
|||||||
className={cn(
|
className={cn(
|
||||||
"invisible-input !text-3xl font-bold text-foreground outline-none placeholder:text-muted-foreground/50 placeholder:hover:text-muted-foreground/80",
|
"invisible-input !text-3xl font-bold text-foreground outline-none placeholder:text-muted-foreground/50 placeholder:hover:text-muted-foreground/80",
|
||||||
title === "" && "max-h-[60px]",
|
title === "" && "max-h-[60px]",
|
||||||
|
error["title"] &&
|
||||||
|
"border-b border-red-600 placeholder:text-red-600/50",
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user