feat: fixed tags
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { IAPITag } from "@/pages/profile_tasks.dto";
|
import { IAPITag, IViewTagsResponse } from "@/pages/profile_tasks.dto";
|
||||||
import apiClient from "@/services/api";
|
import apiClient from "@/services/api";
|
||||||
import { cn } from "@/utils/class-merge";
|
import { cn } from "@/utils/class-merge";
|
||||||
import { BookOpenIcon, CheckIcon, DocumentDuplicateIcon, PlusCircleIcon } from "@heroicons/react/24/outline";
|
import { BookOpenIcon, CheckIcon, DocumentDuplicateIcon, PlusCircleIcon } from "@heroicons/react/24/outline";
|
||||||
@@ -25,7 +25,7 @@ interface ModalTagsProps extends ModalWindowProps {
|
|||||||
first: IAPITag[];
|
first: IAPITag[];
|
||||||
second: IAPITag[];
|
second: IAPITag[];
|
||||||
};
|
};
|
||||||
refreshTags: () => void;
|
refreshTags: () => Promise<IViewTagsResponse | void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ModalTags: FunctionComponent<ModalTagsProps> = ({
|
const ModalTags: FunctionComponent<ModalTagsProps> = ({
|
||||||
@@ -64,7 +64,7 @@ const ModalTags: FunctionComponent<ModalTagsProps> = ({
|
|||||||
{ method: "POST", body: JSON.stringify(data) }
|
{ method: "POST", body: JSON.stringify(data) }
|
||||||
);
|
);
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
refreshTags();
|
await refreshTags();
|
||||||
if (showAddFirstTag) {
|
if (showAddFirstTag) {
|
||||||
const new_subject_id = response.subject!.id;
|
const new_subject_id = response.subject!.id;
|
||||||
onChange!((prev) => ({ ...prev, first: new_subject_id }));
|
onChange!((prev) => ({ ...prev, first: new_subject_id }));
|
||||||
@@ -89,7 +89,7 @@ const ModalTags: FunctionComponent<ModalTagsProps> = ({
|
|||||||
body: JSON.stringify(data),
|
body: JSON.stringify(data),
|
||||||
});
|
});
|
||||||
if (!response.error) {
|
if (!response.error) {
|
||||||
refreshTags();
|
await refreshTags();
|
||||||
} else {
|
} else {
|
||||||
setShowErrorDialog(true);
|
setShowErrorDialog(true);
|
||||||
const match = response.error?.match(/\[(.+)\]/);
|
const match = response.error?.match(/\[(.+)\]/);
|
||||||
|
|||||||
@@ -80,16 +80,7 @@ const ProfileCalendar: FunctionComponent = () => {
|
|||||||
setError,
|
setError,
|
||||||
formState: { errors },
|
formState: { errors },
|
||||||
} = useForm<ITaskForm>({
|
} = useForm<ITaskForm>({
|
||||||
defaultValues: {
|
defaultValues: {},
|
||||||
subject: {
|
|
||||||
name: "",
|
|
||||||
id: 0,
|
|
||||||
},
|
|
||||||
taskType: {
|
|
||||||
name: "",
|
|
||||||
id: 0,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -146,13 +137,13 @@ const ProfileCalendar: FunctionComponent = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ((!editContent?.subject.id || !editContent.taskType.id) && (!tags.first || !tags.second)) {
|
if ((!editContent?.subject.id || !editContent.taskType.id) && (!tags.first || !tags.second)) {
|
||||||
setError("subject", { message: "Выберите теги" });
|
setError("date", { message: "Выберите теги" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const selectedSubject = editContent?.subject.id || tags.first;
|
const selectedSubject = tags.first || editContent?.subject.id;
|
||||||
const selectedTaskType = editContent?.taskType.id || tags.second;
|
const selectedTaskType = tags.second || editContent?.taskType.id;
|
||||||
|
|
||||||
// Format date to DD-MM-YYYYTHH:MM
|
// Format date to DD-MM-YYYYTHH:MM
|
||||||
const formattedDate = calendarDate
|
const formattedDate = calendarDate
|
||||||
@@ -171,8 +162,8 @@ const ProfileCalendar: FunctionComponent = () => {
|
|||||||
const taskData = {
|
const taskData = {
|
||||||
title: data.name,
|
title: data.name,
|
||||||
description: data.description || "",
|
description: data.description || "",
|
||||||
subject: selectedSubject,
|
subject_id: selectedSubject,
|
||||||
taskType: selectedTaskType,
|
taskType_id: selectedTaskType,
|
||||||
dateTime_due: formattedDate,
|
dateTime_due: formattedDate,
|
||||||
telegram_notifications: false,
|
telegram_notifications: false,
|
||||||
priority: selectedPriority,
|
priority: selectedPriority,
|
||||||
@@ -195,7 +186,17 @@ const ProfileCalendar: FunctionComponent = () => {
|
|||||||
|
|
||||||
if (!response.success) {
|
if (!response.success) {
|
||||||
throw new Error(response.message);
|
throw new Error(response.message);
|
||||||
}
|
} else if (isEdit)
|
||||||
|
setEditContent({
|
||||||
|
name: response.task.title,
|
||||||
|
id: response.task.id.toString(),
|
||||||
|
description: response.task.description,
|
||||||
|
priority: response.task.priority,
|
||||||
|
checked: response.task.isCompleted,
|
||||||
|
subject: response.task.subject,
|
||||||
|
taskType: response.task.task_type,
|
||||||
|
date: new Date(response.task.dateTime_due),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
await fetchTasks();
|
await fetchTasks();
|
||||||
@@ -374,35 +375,9 @@ const ProfileCalendar: FunctionComponent = () => {
|
|||||||
month: { className: calendarStyles.month },
|
month: { className: calendarStyles.month },
|
||||||
year: { className: calendarStyles.year },
|
year: { className: calendarStyles.year },
|
||||||
};
|
};
|
||||||
if (isLoading)
|
|
||||||
return (
|
|
||||||
<div class="flex h-full w-full flex-1 flex-col items-center justify-center">
|
|
||||||
<div class="flex w-full flex-1 items-center justify-center">Загрузка...</div>;
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class="flex w-full flex-col items-center">
|
<div class="flex w-full flex-col items-center">
|
||||||
<ModalTags
|
|
||||||
refreshTags={fetchTags}
|
|
||||||
isOpen={openModalTags}
|
|
||||||
setIsOpen={setOpenModalTags}
|
|
||||||
tagsList={example_tags}
|
|
||||||
value={tags}
|
|
||||||
onClose={() => {
|
|
||||||
setTags({ first: 0, second: 0, overdue: false });
|
|
||||||
}}
|
|
||||||
onChange={setTags}
|
|
||||||
/>
|
|
||||||
<ModalCalendar
|
|
||||||
isOpen={openModalCalendar}
|
|
||||||
setIsOpen={setOpenModalCalendar}
|
|
||||||
onClose={() => {
|
|
||||||
if (isEdit && !isEditModal) setCalendarDate(null);
|
|
||||||
}}
|
|
||||||
onChange={(e) => isEditModal && setCalendarDate(e.value)}
|
|
||||||
value={calendarDate!}
|
|
||||||
/>
|
|
||||||
<ModalWindow
|
<ModalWindow
|
||||||
isOpen={openModal}
|
isOpen={openModal}
|
||||||
setIsOpen={setIsOpen}
|
setIsOpen={setIsOpen}
|
||||||
@@ -489,7 +464,6 @@ const ProfileCalendar: FunctionComponent = () => {
|
|||||||
{errors.name && <p class="text-red-500">{errors.name.message}</p>}
|
{errors.name && <p class="text-red-500">{errors.name.message}</p>}
|
||||||
{errors.description && <p class="text-red-500">{errors.description.message}</p>}
|
{errors.description && <p class="text-red-500">{errors.description.message}</p>}
|
||||||
{errors.date && <p class="text-red-500">{errors.date.message}</p>}
|
{errors.date && <p class="text-red-500">{errors.date.message}</p>}
|
||||||
{errors.subject && <p class="text-red-500">{errors.subject.message}</p>}
|
|
||||||
<div class="flex flex-col items-center gap-6 self-center md:flex-row md:justify-start md:self-start">
|
<div class="flex flex-col items-center gap-6 self-center md:flex-row md:justify-start md:self-start">
|
||||||
<div
|
<div
|
||||||
class={cn("flex h-full flex-row items-center gap-1 rounded-2xl bg-[rgba(251,194,199,0.38)] px-2 py-1", {
|
class={cn("flex h-full flex-row items-center gap-1 rounded-2xl bg-[rgba(251,194,199,0.38)] px-2 py-1", {
|
||||||
@@ -544,6 +518,30 @@ const ProfileCalendar: FunctionComponent = () => {
|
|||||||
</form>
|
</form>
|
||||||
)}
|
)}
|
||||||
</ModalWindow>
|
</ModalWindow>
|
||||||
|
{isLoading ? (
|
||||||
|
<div class="flex w-full flex-1 items-center justify-center">Загрузка...</div>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<ModalTags
|
||||||
|
refreshTags={fetchTags}
|
||||||
|
isOpen={openModalTags}
|
||||||
|
setIsOpen={setOpenModalTags}
|
||||||
|
tagsList={example_tags}
|
||||||
|
value={tags}
|
||||||
|
onClose={() => {
|
||||||
|
setTags({ first: 0, second: 0, overdue: false });
|
||||||
|
}}
|
||||||
|
onChange={setTags}
|
||||||
|
/>
|
||||||
|
<ModalCalendar
|
||||||
|
isOpen={openModalCalendar}
|
||||||
|
setIsOpen={setOpenModalCalendar}
|
||||||
|
onClose={() => {
|
||||||
|
if (isEdit && !isEditModal) setCalendarDate(null);
|
||||||
|
}}
|
||||||
|
onChange={(e) => isEditModal && setCalendarDate(e.value)}
|
||||||
|
value={calendarDate!}
|
||||||
|
/>
|
||||||
<Dialog
|
<Dialog
|
||||||
isOpen={showDeleteDialog}
|
isOpen={showDeleteDialog}
|
||||||
setIsOpen={setShowDeleteDialog}
|
setIsOpen={setShowDeleteDialog}
|
||||||
@@ -583,6 +581,8 @@ const ProfileCalendar: FunctionComponent = () => {
|
|||||||
<div class="rounded-lg bg-[rgba(251,194,199,0.2)] p-4 text-center">На этот день задач нет</div>
|
<div class="rounded-lg bg-[rgba(251,194,199,0.2)] p-4 text-center">На этот день задач нет</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ export interface ITaskView extends Omit<ITask, "taskType"> {
|
|||||||
task_type: IAPITag;
|
task_type: IAPITag;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ITaskForm extends Omit<ITask, "date"> {
|
export interface ITaskForm extends Omit<ITask, "date" | "subject" | "taskType"> {
|
||||||
date: string;
|
date: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,15 +80,11 @@ export interface IEditTaskResponse {
|
|||||||
id: number;
|
id: number;
|
||||||
title: string;
|
title: string;
|
||||||
description: string;
|
description: string;
|
||||||
subject: string;
|
subject: IAPITag;
|
||||||
taskType: string;
|
task_type: IAPITag;
|
||||||
dateTime_due: string;
|
dateTime_due: string;
|
||||||
isCompleted: boolean;
|
isCompleted: boolean;
|
||||||
reminder?: {
|
priority: number;
|
||||||
remind_before_days: number;
|
|
||||||
repeat_interval: number;
|
|
||||||
reminder_time: string;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ import { Dropdown } from "primereact/dropdown";
|
|||||||
import { SelectItem } from "primereact/selectitem";
|
import { SelectItem } from "primereact/selectitem";
|
||||||
import { Nullable } from "primereact/ts-helpers";
|
import { Nullable } from "primereact/ts-helpers";
|
||||||
import { SubmitHandler, useForm } from "react-hook-form";
|
import { SubmitHandler, useForm } from "react-hook-form";
|
||||||
import { v4 as uuid } from "uuid";
|
|
||||||
import {
|
import {
|
||||||
IApiResponse,
|
IApiResponse,
|
||||||
IAPITag,
|
IAPITag,
|
||||||
@@ -87,7 +86,7 @@ const ProfileTasks: FunctionComponent = () => {
|
|||||||
fetchTags();
|
fetchTags();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const fetchTags = async () => {
|
const fetchTags = async (): Promise<IViewTagsResponse | void> => {
|
||||||
try {
|
try {
|
||||||
const response = await apiClient<IViewTagsResponse>("/api/tags/view_tags/");
|
const response = await apiClient<IViewTagsResponse>("/api/tags/view_tags/");
|
||||||
setSubjectChoices(response.subjects);
|
setSubjectChoices(response.subjects);
|
||||||
@@ -126,18 +125,7 @@ const ProfileTasks: FunctionComponent = () => {
|
|||||||
reset,
|
reset,
|
||||||
setError,
|
setError,
|
||||||
formState: { errors },
|
formState: { errors },
|
||||||
} = useForm<ITaskForm>({
|
} = useForm<ITaskForm>({});
|
||||||
defaultValues: {
|
|
||||||
subject: {
|
|
||||||
name: "",
|
|
||||||
id: 0,
|
|
||||||
},
|
|
||||||
taskType: {
|
|
||||||
name: "",
|
|
||||||
id: 0,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const example_tags = useMemo(
|
const example_tags = useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
@@ -153,7 +141,7 @@ const ProfileTasks: FunctionComponent = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ((!editContent?.subject.id || !editContent.taskType.id) && (!tags.first || !tags.second)) {
|
if ((!editContent?.subject.id || !editContent.taskType.id) && (!tags.first || !tags.second)) {
|
||||||
setError("subject", { message: "Выберите теги" });
|
setError("date", { message: "Выберите теги" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,11 +190,20 @@ const ProfileTasks: FunctionComponent = () => {
|
|||||||
|
|
||||||
if (!response.success) {
|
if (!response.success) {
|
||||||
throw new Error(response.message);
|
throw new Error(response.message);
|
||||||
}
|
} else if (isEdit)
|
||||||
|
setEditContent({
|
||||||
|
name: response.task.title,
|
||||||
|
id: response.task.id.toString(),
|
||||||
|
description: response.task.description,
|
||||||
|
priority: response.task.priority,
|
||||||
|
checked: response.task.isCompleted,
|
||||||
|
subject: response.task.subject,
|
||||||
|
taskType: response.task.task_type,
|
||||||
|
date: new Date(response.task.dateTime_due),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
await fetchTasks();
|
await fetchTasks();
|
||||||
|
|
||||||
if (isCreating) setIsOpen(false);
|
if (isCreating) setIsOpen(false);
|
||||||
setTags({ first: 0, second: 0, overdue: false });
|
setTags({ first: 0, second: 0, overdue: false });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -223,14 +220,6 @@ const ProfileTasks: FunctionComponent = () => {
|
|||||||
name: "",
|
name: "",
|
||||||
description: "",
|
description: "",
|
||||||
date: "",
|
date: "",
|
||||||
subject: {
|
|
||||||
name: "",
|
|
||||||
id: 0,
|
|
||||||
},
|
|
||||||
taskType: {
|
|
||||||
name: "",
|
|
||||||
id: 0,
|
|
||||||
},
|
|
||||||
priority: 4,
|
priority: 4,
|
||||||
checked: false,
|
checked: false,
|
||||||
});
|
});
|
||||||
@@ -385,37 +374,8 @@ const ProfileTasks: FunctionComponent = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (isLoading)
|
|
||||||
return (
|
|
||||||
<div class="flex h-full w-full flex-1 flex-col items-center justify-center">
|
|
||||||
<div class="flex w-full flex-1 items-center justify-center">Загрузка...</div>;
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class={classes.container}>
|
<div class={classes.container}>
|
||||||
<ModalTags
|
|
||||||
refreshTags={fetchTags}
|
|
||||||
zIndex={70}
|
|
||||||
isOpen={openModalTags}
|
|
||||||
setIsOpen={setOpenModalTags}
|
|
||||||
tagsList={example_tags}
|
|
||||||
value={tags}
|
|
||||||
onClose={() => {
|
|
||||||
if (!isCreating) setTags({ first: 0, second: 0, overdue: false });
|
|
||||||
}}
|
|
||||||
onChange={setTags}
|
|
||||||
/>
|
|
||||||
<ModalCalendar
|
|
||||||
zIndex={80}
|
|
||||||
isOpen={openModalCalendar}
|
|
||||||
setIsOpen={setOpenModalCalendar}
|
|
||||||
onClose={() => {
|
|
||||||
if (isEdit && !isEditModal) setCalendarDate(null);
|
|
||||||
}}
|
|
||||||
onChange={(e) => (isCreating || isEditModal) && setCalendarDate(e.value)}
|
|
||||||
value={calendarDate!}
|
|
||||||
/>
|
|
||||||
<ModalWindow
|
<ModalWindow
|
||||||
zIndex={60}
|
zIndex={60}
|
||||||
isOpen={openModal}
|
isOpen={openModal}
|
||||||
@@ -504,7 +464,6 @@ const ProfileTasks: FunctionComponent = () => {
|
|||||||
{errors.name && <p class="text-red-500">{errors.name.message}</p>}
|
{errors.name && <p class="text-red-500">{errors.name.message}</p>}
|
||||||
{errors.description && <p class="text-red-500">{errors.description.message}</p>}
|
{errors.description && <p class="text-red-500">{errors.description.message}</p>}
|
||||||
{errors.date && <p class="text-red-500">{errors.date.message}</p>}
|
{errors.date && <p class="text-red-500">{errors.date.message}</p>}
|
||||||
{errors.subject && <p class="text-red-500">{errors.subject.message}</p>}
|
|
||||||
<div class="flex flex-col items-center gap-6 self-center md:flex-row md:justify-start md:self-start">
|
<div class="flex flex-col items-center gap-6 self-center md:flex-row md:justify-start md:self-start">
|
||||||
<div
|
<div
|
||||||
class={cn("flex h-full flex-row items-center gap-1 rounded-2xl bg-[rgba(251,194,199,0.38)] px-2 py-1", {
|
class={cn("flex h-full flex-row items-center gap-1 rounded-2xl bg-[rgba(251,194,199,0.38)] px-2 py-1", {
|
||||||
@@ -524,7 +483,7 @@ const ProfileTasks: FunctionComponent = () => {
|
|||||||
year: "numeric",
|
year: "numeric",
|
||||||
hour: "2-digit",
|
hour: "2-digit",
|
||||||
minute: "2-digit",
|
minute: "2-digit",
|
||||||
}).format(calendarDate!)}
|
}).format(calendarDate ?? editContent.date)}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
@@ -563,7 +522,7 @@ const ProfileTasks: FunctionComponent = () => {
|
|||||||
class="flex h-full w-full flex-col items-start justify-between"
|
class="flex h-full w-full flex-col items-start justify-between"
|
||||||
onSubmit={(e) => {
|
onSubmit={(e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
handleSubmit((data) => saveTask({ ...data, id: uuid() }))();
|
handleSubmit((data) => saveTask(data))();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div class="flex w-full flex-1 flex-row items-start justify-between">
|
<div class="flex w-full flex-1 flex-row items-start justify-between">
|
||||||
@@ -609,7 +568,6 @@ const ProfileTasks: FunctionComponent = () => {
|
|||||||
</div>
|
</div>
|
||||||
{errors.name && <p class="text-red-500">{errors.name.message}</p>}
|
{errors.name && <p class="text-red-500">{errors.name.message}</p>}
|
||||||
{errors.date && <p class="text-red-500">{errors.date.message}</p>}
|
{errors.date && <p class="text-red-500">{errors.date.message}</p>}
|
||||||
{errors.subject?.message && <p class="text-red-500">{errors.subject.message}</p>}
|
|
||||||
<div className="mb-8 flex h-16 flex-col items-center gap-6 self-center md:mb-0 md:flex-row md:self-start">
|
<div className="mb-8 flex h-16 flex-col items-center gap-6 self-center md:mb-0 md:flex-row md:self-start">
|
||||||
<Button
|
<Button
|
||||||
className="text-sm"
|
className="text-sm"
|
||||||
@@ -626,6 +584,32 @@ const ProfileTasks: FunctionComponent = () => {
|
|||||||
</form>
|
</form>
|
||||||
)}
|
)}
|
||||||
</ModalWindow>
|
</ModalWindow>
|
||||||
|
{isLoading ? (
|
||||||
|
<div class="flex w-full flex-1 items-center justify-center">Загрузка...</div>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<ModalTags
|
||||||
|
refreshTags={fetchTags}
|
||||||
|
zIndex={70}
|
||||||
|
isOpen={openModalTags}
|
||||||
|
setIsOpen={setOpenModalTags}
|
||||||
|
tagsList={example_tags}
|
||||||
|
value={tags}
|
||||||
|
onClose={() => {
|
||||||
|
if (!isCreating) setTags({ first: 0, second: 0, overdue: false });
|
||||||
|
}}
|
||||||
|
onChange={setTags}
|
||||||
|
/>
|
||||||
|
<ModalCalendar
|
||||||
|
zIndex={80}
|
||||||
|
isOpen={openModalCalendar}
|
||||||
|
setIsOpen={setOpenModalCalendar}
|
||||||
|
onClose={() => {
|
||||||
|
if (isEdit && !isEditModal) setCalendarDate(null);
|
||||||
|
}}
|
||||||
|
onChange={(e) => (isCreating || isEditModal) && setCalendarDate(e.value)}
|
||||||
|
value={calendarDate!}
|
||||||
|
/>
|
||||||
<Dialog
|
<Dialog
|
||||||
isOpen={showDeleteDialog}
|
isOpen={showDeleteDialog}
|
||||||
setIsOpen={setShowDeleteDialog}
|
setIsOpen={setShowDeleteDialog}
|
||||||
@@ -977,6 +961,8 @@ const ProfileTasks: FunctionComponent = () => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user