refactor: quick add (#2541)
* refactor: store and helper setup for quick-add * refactor: kanban quick add with optimistic issue create * refactor: added function definition * refactor: list quick add with optimistic issue create * refactor: spreadsheet quick add with optimistic issue create * refactor: calender quick add with optimistic issue create * refactor: gantt quick add with optimistic issue create * refactor: input component and pre-loading data logic * style: calender quick-add height and content shift * feat: sub-group quick-add issue * feat: displaying loading state when issue is being created * fix: setting string null to null
This commit is contained in:
parent
d95ea463b2
commit
4aad35e007
35 changed files with 2734 additions and 951 deletions
|
|
@ -44,12 +44,23 @@ export const CalendarChart: React.FC<Props> = observer((props) => {
|
|||
<div className="h-full w-full grid grid-cols-1 divide-y-[0.5px] divide-custom-border-200">
|
||||
{allWeeksOfActiveMonth &&
|
||||
Object.values(allWeeksOfActiveMonth).map((week: ICalendarWeek, weekIndex) => (
|
||||
<CalendarWeekDays key={weekIndex} week={week} issues={issues} quickActions={quickActions} />
|
||||
<CalendarWeekDays
|
||||
key={weekIndex}
|
||||
week={week}
|
||||
issues={issues}
|
||||
enableQuickIssueCreate
|
||||
quickActions={quickActions}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
{layout === "week" && (
|
||||
<CalendarWeekDays week={calendarStore.allDaysOfActiveWeek} issues={issues} quickActions={quickActions} />
|
||||
<CalendarWeekDays
|
||||
week={calendarStore.allDaysOfActiveWeek}
|
||||
issues={issues}
|
||||
enableQuickIssueCreate
|
||||
quickActions={quickActions}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import { Droppable } from "@hello-pangea/dnd";
|
|||
// mobx store
|
||||
import { useMobxStore } from "lib/mobx/store-provider";
|
||||
// components
|
||||
import { CalendarIssueBlocks, ICalendarDate } from "components/issues";
|
||||
import { CalendarIssueBlocks, ICalendarDate, CalendarInlineCreateIssueForm } from "components/issues";
|
||||
// helpers
|
||||
import { renderDateFormat } from "helpers/date-time.helper";
|
||||
// types
|
||||
|
|
@ -17,10 +17,11 @@ type Props = {
|
|||
date: ICalendarDate;
|
||||
issues: IIssueGroupedStructure | null;
|
||||
quickActions: (issue: IIssue) => React.ReactNode;
|
||||
enableQuickIssueCreate?: boolean;
|
||||
};
|
||||
|
||||
export const CalendarDayTile: React.FC<Props> = observer((props) => {
|
||||
const { date, issues, quickActions } = props;
|
||||
const { date, issues, quickActions, enableQuickIssueCreate } = props;
|
||||
|
||||
const { issueFilter: issueFilterStore } = useMobxStore();
|
||||
|
||||
|
|
@ -30,7 +31,7 @@ export const CalendarDayTile: React.FC<Props> = observer((props) => {
|
|||
|
||||
return (
|
||||
<>
|
||||
<div className="w-full h-full relative flex flex-col bg-custom-background-90">
|
||||
<div className="group w-full h-full relative flex flex-col bg-custom-background-90">
|
||||
{/* header */}
|
||||
<div
|
||||
className={`text-xs text-right flex-shrink-0 py-1 px-2 ${
|
||||
|
|
@ -63,6 +64,16 @@ export const CalendarDayTile: React.FC<Props> = observer((props) => {
|
|||
ref={provided.innerRef}
|
||||
>
|
||||
<CalendarIssueBlocks issues={issuesList} quickActions={quickActions} />
|
||||
{enableQuickIssueCreate && (
|
||||
<div className="py-1 px-2">
|
||||
<CalendarInlineCreateIssueForm
|
||||
groupId={renderDateFormat(date.date)}
|
||||
prePopulatedData={{
|
||||
target_date: renderDateFormat(date.date),
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
{provided.placeholder}
|
||||
</div>
|
||||
)}
|
||||
|
|
|
|||
|
|
@ -7,3 +7,4 @@ export * from "./header";
|
|||
export * from "./issue-blocks";
|
||||
export * from "./week-days";
|
||||
export * from "./week-header";
|
||||
export * from "./inline-create-issue-form";
|
||||
|
|
|
|||
|
|
@ -0,0 +1,234 @@
|
|||
import { useEffect, useRef, useState } from "react";
|
||||
import { useRouter } from "next/router";
|
||||
import { Transition } from "@headlessui/react";
|
||||
import { useForm } from "react-hook-form";
|
||||
|
||||
// store
|
||||
import { observer } from "mobx-react-lite";
|
||||
import { useMobxStore } from "lib/mobx/store-provider";
|
||||
|
||||
// hooks
|
||||
import useToast from "hooks/use-toast";
|
||||
import useKeypress from "hooks/use-keypress";
|
||||
import useProjectDetails from "hooks/use-project-details";
|
||||
import useOutsideClickDetector from "hooks/use-outside-click-detector";
|
||||
|
||||
// constants
|
||||
import { createIssuePayload } from "constants/issue";
|
||||
|
||||
// icons
|
||||
import { PlusIcon } from "lucide-react";
|
||||
|
||||
// types
|
||||
import { IIssue } from "types";
|
||||
|
||||
type Props = {
|
||||
groupId?: string;
|
||||
dependencies?: any[];
|
||||
prePopulatedData?: Partial<IIssue>;
|
||||
onSuccess?: (data: IIssue) => Promise<void> | void;
|
||||
};
|
||||
|
||||
const useCheckIfThereIsSpaceOnRight = (ref: React.RefObject<HTMLDivElement>, deps: any[]) => {
|
||||
const [isThereSpaceOnRight, setIsThereSpaceOnRight] = useState(true);
|
||||
|
||||
const router = useRouter();
|
||||
const { moduleId, cycleId, viewId } = router.query;
|
||||
|
||||
const container = document.getElementById(`calendar-view-${cycleId ?? moduleId ?? viewId}`);
|
||||
|
||||
useEffect(() => {
|
||||
if (!ref.current) return;
|
||||
|
||||
const { right } = ref.current.getBoundingClientRect();
|
||||
|
||||
const width = right;
|
||||
|
||||
const innerWidth = container?.getBoundingClientRect().width ?? window.innerWidth;
|
||||
|
||||
if (width > innerWidth) setIsThereSpaceOnRight(false);
|
||||
else setIsThereSpaceOnRight(true);
|
||||
}, [ref, deps, container]);
|
||||
|
||||
return isThereSpaceOnRight;
|
||||
};
|
||||
|
||||
const defaultValues: Partial<IIssue> = {
|
||||
name: "",
|
||||
};
|
||||
|
||||
const Inputs = (props: any) => {
|
||||
const { register, setFocus, projectDetails } = props;
|
||||
|
||||
useEffect(() => {
|
||||
setFocus("name");
|
||||
}, [setFocus]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<h4 className="text-sm font-medium leading-5 text-custom-text-400">{projectDetails?.identifier ?? "..."}</h4>
|
||||
<input
|
||||
type="text"
|
||||
autoComplete="off"
|
||||
placeholder="Issue Title"
|
||||
{...register("name", {
|
||||
required: "Issue title is required.",
|
||||
})}
|
||||
className="w-full pr-2 py-1.5 rounded-md bg-transparent text-sm font-medium leading-5 text-custom-text-200 outline-none"
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export const CalendarInlineCreateIssueForm: React.FC<Props> = observer((props) => {
|
||||
const { prePopulatedData, dependencies = [], groupId } = props;
|
||||
|
||||
// router
|
||||
const router = useRouter();
|
||||
const { workspaceSlug, projectId } = router.query;
|
||||
|
||||
// store
|
||||
const { workspace: workspaceStore, quickAddIssue: quickAddStore } = useMobxStore();
|
||||
|
||||
// ref
|
||||
const ref = useRef<HTMLDivElement>(null);
|
||||
|
||||
// states
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
|
||||
const { setToastAlert } = useToast();
|
||||
|
||||
const { projectDetails } = useProjectDetails();
|
||||
|
||||
const {
|
||||
reset,
|
||||
handleSubmit,
|
||||
register,
|
||||
setFocus,
|
||||
formState: { errors, isSubmitting },
|
||||
} = useForm<IIssue>({ defaultValues });
|
||||
|
||||
const handleClose = () => {
|
||||
setIsOpen(false);
|
||||
};
|
||||
|
||||
useKeypress("Escape", handleClose);
|
||||
useOutsideClickDetector(ref, handleClose);
|
||||
|
||||
// derived values
|
||||
const workspaceDetail = workspaceStore.getWorkspaceBySlug(workspaceSlug?.toString()!);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isOpen) reset({ ...defaultValues });
|
||||
}, [isOpen, reset]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!errors) return;
|
||||
|
||||
Object.keys(errors).forEach((key) => {
|
||||
const error = errors[key as keyof IIssue];
|
||||
|
||||
setToastAlert({
|
||||
type: "error",
|
||||
title: "Error!",
|
||||
message: error?.message?.toString() || "Some error occurred. Please try again.",
|
||||
});
|
||||
});
|
||||
}, [errors, setToastAlert]);
|
||||
|
||||
const isSpaceOnRight = useCheckIfThereIsSpaceOnRight(ref, dependencies);
|
||||
|
||||
const onSubmitHandler = async (formData: IIssue) => {
|
||||
if (isSubmitting || !workspaceSlug || !projectId) return;
|
||||
|
||||
// resetting the form so that user can add another issue quickly
|
||||
reset({ ...defaultValues, ...(prePopulatedData ?? {}) });
|
||||
|
||||
const payload = createIssuePayload(workspaceDetail!, projectDetails!, {
|
||||
...(prePopulatedData ?? {}),
|
||||
...formData,
|
||||
labels_list:
|
||||
formData.labels_list?.length !== 0
|
||||
? formData.labels_list
|
||||
: prePopulatedData?.labels && prePopulatedData?.labels.toString() !== "none"
|
||||
? [prePopulatedData.labels as any]
|
||||
: [],
|
||||
assignees_list:
|
||||
formData.assignees_list?.length !== 0
|
||||
? formData.assignees_list
|
||||
: prePopulatedData?.assignees && prePopulatedData?.assignees.toString() !== "none"
|
||||
? [prePopulatedData.assignees as any]
|
||||
: [],
|
||||
});
|
||||
|
||||
try {
|
||||
quickAddStore.createIssue(
|
||||
workspaceSlug.toString(),
|
||||
projectId.toString(),
|
||||
{
|
||||
group_id: groupId ?? null,
|
||||
sub_group_id: null,
|
||||
},
|
||||
payload
|
||||
);
|
||||
|
||||
setToastAlert({
|
||||
type: "success",
|
||||
title: "Success!",
|
||||
message: "Issue created successfully.",
|
||||
});
|
||||
} catch (err: any) {
|
||||
Object.keys(err || {}).forEach((key) => {
|
||||
const error = err?.[key];
|
||||
const errorTitle = error ? (Array.isArray(error) ? error.join(", ") : error) : null;
|
||||
|
||||
setToastAlert({
|
||||
type: "error",
|
||||
title: "Error!",
|
||||
message: errorTitle || "Some error occurred. Please try again.",
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Transition
|
||||
show={isOpen}
|
||||
enter="transition ease-in-out duration-200 transform"
|
||||
enterFrom="opacity-0 scale-95"
|
||||
enterTo="opacity-100 scale-100"
|
||||
leave="transition ease-in-out duration-200 transform"
|
||||
leaveFrom="opacity-100 scale-100"
|
||||
leaveTo="opacity-0 scale-95"
|
||||
>
|
||||
<div
|
||||
ref={ref}
|
||||
className={`transition-all z-20 w-full ${
|
||||
isOpen ? "opacity-100 scale-100" : "opacity-0 pointer-events-none scale-95"
|
||||
}`}
|
||||
>
|
||||
<form
|
||||
onSubmit={handleSubmit(onSubmitHandler)}
|
||||
className="flex w-full px-1.5 border-[0.5px] border-custom-border-100 rounded z-50 items-center gap-x-2 bg-custom-background-100 shadow-custom-shadow-sm transition-opacity"
|
||||
>
|
||||
<Inputs register={register} setFocus={setFocus} projectDetails={projectDetails} />
|
||||
</form>
|
||||
</div>
|
||||
</Transition>
|
||||
|
||||
{!isOpen && (
|
||||
<div className="hidden group-hover:block border-[0.5px] border-custom-border-200 rounded">
|
||||
<button
|
||||
type="button"
|
||||
className="w-full flex items-center gap-x-[6px] text-custom-primary-100 px-1 py-1.5 rounded-md"
|
||||
onClick={() => setIsOpen(true)}
|
||||
>
|
||||
<PlusIcon className="h-4 w-4" />
|
||||
<span className="text-sm font-medium text-custom-primary-100">New Issue</span>
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
});
|
||||
|
|
@ -22,11 +22,14 @@ export const CalendarIssueBlocks: React.FC<Props> = observer((props) => {
|
|||
<Draggable key={issue.id} draggableId={issue.id} index={index}>
|
||||
{(provided, snapshot) => (
|
||||
<div
|
||||
className="p-1 px-2"
|
||||
className="p-1 px-2 relative"
|
||||
{...provided.draggableProps}
|
||||
{...provided.dragHandleProps}
|
||||
ref={provided.innerRef}
|
||||
>
|
||||
{issue?.tempId !== undefined && (
|
||||
<div className="absolute top-0 left-0 w-full h-full animate-pulse bg-custom-background-100/20 z-[99999]" />
|
||||
)}
|
||||
<Link href={`/${workspaceSlug?.toString()}/projects/${issue.project}/issues/${issue.id}`}>
|
||||
<a
|
||||
className={`group/calendar-block h-8 w-full shadow-custom-shadow-2xs rounded py-1.5 px-1 flex items-center gap-1.5 border-[0.5px] border-custom-border-100 ${
|
||||
|
|
@ -46,11 +49,6 @@ export const CalendarIssueBlocks: React.FC<Props> = observer((props) => {
|
|||
</div>
|
||||
<h6 className="text-xs flex-grow truncate">{issue.name}</h6>
|
||||
<div className="hidden group-hover/calendar-block:block">{quickActions(issue)}</div>
|
||||
{/* <IssueQuickActions
|
||||
issue={issue}
|
||||
handleDelete={async () => handleIssues(issue.target_date ?? "", issue, "delete")}
|
||||
handleUpdate={async (data) => handleIssues(issue.target_date ?? "", data, "update")}
|
||||
/> */}
|
||||
</a>
|
||||
</Link>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -15,10 +15,11 @@ type Props = {
|
|||
issues: IIssueGroupedStructure | null;
|
||||
week: ICalendarWeek | undefined;
|
||||
quickActions: (issue: IIssue) => React.ReactNode;
|
||||
enableQuickIssueCreate?: boolean;
|
||||
};
|
||||
|
||||
export const CalendarWeekDays: React.FC<Props> = observer((props) => {
|
||||
const { issues, week, quickActions } = props;
|
||||
const { issues, week, quickActions, enableQuickIssueCreate } = props;
|
||||
|
||||
const { issueFilter: issueFilterStore } = useMobxStore();
|
||||
|
||||
|
|
@ -37,7 +38,13 @@ export const CalendarWeekDays: React.FC<Props> = observer((props) => {
|
|||
if (!showWeekends && (date.date.getDay() === 0 || date.date.getDay() === 6)) return null;
|
||||
|
||||
return (
|
||||
<CalendarDayTile key={renderDateFormat(date.date)} date={date} issues={issues} quickActions={quickActions} />
|
||||
<CalendarDayTile
|
||||
key={renderDateFormat(date.date)}
|
||||
date={date}
|
||||
issues={issues}
|
||||
quickActions={quickActions}
|
||||
enableQuickIssueCreate={enableQuickIssueCreate}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -3,3 +3,4 @@ export * from "./cycle-root";
|
|||
export * from "./module-root";
|
||||
export * from "./project-view-root";
|
||||
export * from "./root";
|
||||
export * from "./inline-create-issue-form";
|
||||
|
|
|
|||
|
|
@ -0,0 +1,196 @@
|
|||
import { useEffect, useState, useRef } from "react";
|
||||
import { useRouter } from "next/router";
|
||||
import { useForm } from "react-hook-form";
|
||||
import { Transition } from "@headlessui/react";
|
||||
import { PlusIcon } from "lucide-react";
|
||||
|
||||
// store
|
||||
import { observer } from "mobx-react-lite";
|
||||
import { useMobxStore } from "lib/mobx/store-provider";
|
||||
|
||||
// constants
|
||||
import { createIssuePayload } from "constants/issue";
|
||||
|
||||
// hooks
|
||||
import useToast from "hooks/use-toast";
|
||||
import useKeypress from "hooks/use-keypress";
|
||||
import useProjectDetails from "hooks/use-project-details";
|
||||
import useOutsideClickDetector from "hooks/use-outside-click-detector";
|
||||
|
||||
// types
|
||||
import { IIssue } from "types";
|
||||
import { renderDateFormat } from "helpers/date-time.helper";
|
||||
|
||||
type Props = {
|
||||
prePopulatedData?: Partial<IIssue>;
|
||||
onSuccess?: (data: IIssue) => Promise<void> | void;
|
||||
};
|
||||
|
||||
const defaultValues: Partial<IIssue> = {
|
||||
name: "",
|
||||
};
|
||||
|
||||
const Inputs = (props: any) => {
|
||||
const { register, setFocus } = props;
|
||||
|
||||
useEffect(() => {
|
||||
setFocus("name");
|
||||
}, [setFocus]);
|
||||
|
||||
return (
|
||||
<input
|
||||
type="text"
|
||||
autoComplete="off"
|
||||
placeholder="Issue Title"
|
||||
{...register("name", {
|
||||
required: "Issue title is required.",
|
||||
})}
|
||||
className="w-full px-2 rounded-md bg-transparent text-sm font-medium leading-5 text-custom-text-200 outline-none"
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export const GanttInlineCreateIssueForm: React.FC<Props> = observer((props) => {
|
||||
const { prePopulatedData } = props;
|
||||
|
||||
// router
|
||||
const router = useRouter();
|
||||
const { workspaceSlug, projectId } = router.query;
|
||||
|
||||
// store
|
||||
const { workspace: workspaceStore, quickAddIssue: quickAddStore } = useMobxStore();
|
||||
|
||||
const { projectDetails } = useProjectDetails();
|
||||
|
||||
const {
|
||||
reset,
|
||||
handleSubmit,
|
||||
setFocus,
|
||||
register,
|
||||
formState: { errors, isSubmitting },
|
||||
} = useForm<IIssue>({ defaultValues });
|
||||
|
||||
// ref
|
||||
const ref = useRef<HTMLFormElement>(null);
|
||||
|
||||
// states
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
|
||||
const handleClose = () => setIsOpen(false);
|
||||
|
||||
// hooks
|
||||
useKeypress("Escape", handleClose);
|
||||
useOutsideClickDetector(ref, handleClose);
|
||||
const { setToastAlert } = useToast();
|
||||
|
||||
// derived values
|
||||
const workspaceDetail = workspaceStore.getWorkspaceBySlug(workspaceSlug?.toString()!);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isOpen) reset({ ...defaultValues });
|
||||
}, [isOpen, reset]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!errors) return;
|
||||
|
||||
Object.keys(errors).forEach((key) => {
|
||||
const error = errors[key as keyof IIssue];
|
||||
|
||||
setToastAlert({
|
||||
type: "error",
|
||||
title: "Error!",
|
||||
message: error?.message?.toString() || "Some error occurred. Please try again.",
|
||||
});
|
||||
});
|
||||
}, [errors, setToastAlert]);
|
||||
|
||||
const onSubmitHandler = async (formData: IIssue) => {
|
||||
if (isSubmitting || !workspaceSlug || !projectId) return;
|
||||
|
||||
// resetting the form so that user can add another issue quickly
|
||||
reset({ ...defaultValues, ...(prePopulatedData ?? {}) });
|
||||
|
||||
const payload = createIssuePayload(workspaceDetail!, projectDetails!, {
|
||||
...(prePopulatedData ?? {}),
|
||||
...formData,
|
||||
labels_list:
|
||||
formData.labels_list?.length !== 0
|
||||
? formData.labels_list
|
||||
: prePopulatedData?.labels && prePopulatedData?.labels.toString() !== "none"
|
||||
? [prePopulatedData.labels as any]
|
||||
: [],
|
||||
start_date: renderDateFormat(new Date()),
|
||||
target_date: renderDateFormat(new Date(new Date().getTime() + 24 * 60 * 60 * 1000)),
|
||||
});
|
||||
|
||||
try {
|
||||
quickAddStore.createIssue(
|
||||
workspaceSlug.toString(),
|
||||
projectId.toString(),
|
||||
{
|
||||
group_id: null,
|
||||
sub_group_id: null,
|
||||
},
|
||||
payload
|
||||
);
|
||||
|
||||
setToastAlert({
|
||||
type: "success",
|
||||
title: "Success!",
|
||||
message: "Issue created successfully.",
|
||||
});
|
||||
} catch (err: any) {
|
||||
Object.keys(err || {}).forEach((key) => {
|
||||
const error = err?.[key];
|
||||
const errorTitle = error ? (Array.isArray(error) ? error.join(", ") : error) : null;
|
||||
|
||||
setToastAlert({
|
||||
type: "error",
|
||||
title: "Error!",
|
||||
message: errorTitle || "Some error occurred. Please try again.",
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Transition
|
||||
show={isOpen}
|
||||
enter="transition ease-in-out duration-200 transform"
|
||||
enterFrom="opacity-0 scale-95"
|
||||
enterTo="opacity-100 scale-100"
|
||||
leave="transition ease-in-out duration-200 transform"
|
||||
leaveFrom="opacity-100 scale-100"
|
||||
leaveTo="opacity-0 scale-95"
|
||||
>
|
||||
<form
|
||||
ref={ref}
|
||||
className="flex py-3 px-4 border-[0.5px] border-custom-border-100 mr-2.5 items-center rounded gap-x-2 bg-custom-background-100 shadow-custom-shadow-sm"
|
||||
onSubmit={handleSubmit(onSubmitHandler)}
|
||||
>
|
||||
<div className="w-[14px] h-[14px] rounded-full border border-custom-border-1000 flex-shrink-0" />
|
||||
<h4 className="text-sm text-custom-text-400">{projectDetails?.identifier ?? "..."}</h4>
|
||||
<Inputs register={register} setFocus={setFocus} />
|
||||
</form>
|
||||
</Transition>
|
||||
|
||||
{isOpen && (
|
||||
<p className="text-xs ml-3 mt-3 italic text-custom-text-200">
|
||||
Press {"'"}Enter{"'"} to add another issue
|
||||
</p>
|
||||
)}
|
||||
|
||||
{!isOpen && (
|
||||
<button
|
||||
type="button"
|
||||
className="flex items-center gap-x-[6px] text-custom-primary-100 px-2 py-1 rounded-md"
|
||||
onClick={() => setIsOpen(true)}
|
||||
>
|
||||
<PlusIcon className="h-4 w-4" />
|
||||
<span className="text-sm font-medium text-custom-primary-100">New Issue</span>
|
||||
</button>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
});
|
||||
|
|
@ -54,6 +54,9 @@ export const KanbanIssueBlock: React.FC<IssueBlockProps> = (props) => {
|
|||
{...provided.dragHandleProps}
|
||||
ref={provided.innerRef}
|
||||
>
|
||||
{issue.tempId !== undefined && (
|
||||
<div className="absolute top-0 left-0 w-full h-full animate-pulse bg-custom-background-100/20 z-[99999]" />
|
||||
)}
|
||||
<div className="absolute top-3 right-3 hidden group-hover/kanban-block:block">
|
||||
{quickActions(
|
||||
!sub_group_id && sub_group_id === "null" ? null : sub_group_id,
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import { Droppable } from "@hello-pangea/dnd";
|
|||
import { useMobxStore } from "lib/mobx/store-provider";
|
||||
// components
|
||||
import { KanBanGroupByHeaderRoot } from "./headers/group-by-root";
|
||||
import { KanbanIssueBlocksList } from "components/issues";
|
||||
import { KanbanIssueBlocksList, BoardInlineCreateIssueForm } from "components/issues";
|
||||
// types
|
||||
import { IEstimatePoint, IIssue, IIssueLabels, IProject, IState, IUserLite } from "types";
|
||||
// constants
|
||||
|
|
@ -29,6 +29,7 @@ export interface IGroupByKanBan {
|
|||
display_properties: any;
|
||||
kanBanToggle: any;
|
||||
handleKanBanToggle: any;
|
||||
enableQuickIssueCreate?: boolean;
|
||||
states: IState[] | null;
|
||||
labels: IIssueLabels[] | null;
|
||||
members: IUserLite[] | null;
|
||||
|
|
@ -55,6 +56,7 @@ const GroupByKanBan: React.FC<IGroupByKanBan> = observer((props) => {
|
|||
members,
|
||||
priorities,
|
||||
estimates,
|
||||
enableQuickIssueCreate,
|
||||
} = props;
|
||||
|
||||
const verticalAlignPosition = (_list: any) =>
|
||||
|
|
@ -120,6 +122,16 @@ const GroupByKanBan: React.FC<IGroupByKanBan> = observer((props) => {
|
|||
)}
|
||||
</Droppable>
|
||||
</div>
|
||||
{enableQuickIssueCreate && (
|
||||
<BoardInlineCreateIssueForm
|
||||
groupId={getValueFromObject(_list, listKey) as string}
|
||||
subGroupId={sub_group_id}
|
||||
prePopulatedData={{
|
||||
...(group_by && { [group_by]: getValueFromObject(_list, listKey) }),
|
||||
...(sub_group_by && sub_group_id !== "null" && { [sub_group_by]: sub_group_id }),
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
|
@ -149,6 +161,7 @@ export interface IKanBan {
|
|||
members: IUserLite[] | null;
|
||||
projects: IProject[] | null;
|
||||
estimates: IEstimatePoint[] | null;
|
||||
enableQuickIssueCreate?: boolean;
|
||||
}
|
||||
|
||||
export const KanBan: React.FC<IKanBan> = observer((props) => {
|
||||
|
|
@ -169,6 +182,7 @@ export const KanBan: React.FC<IKanBan> = observer((props) => {
|
|||
members,
|
||||
projects,
|
||||
estimates,
|
||||
enableQuickIssueCreate,
|
||||
} = props;
|
||||
|
||||
const { project: projectStore, issueKanBanView: issueKanBanViewStore } = useMobxStore();
|
||||
|
|
@ -189,6 +203,7 @@ export const KanBan: React.FC<IKanBan> = observer((props) => {
|
|||
display_properties={display_properties}
|
||||
kanBanToggle={kanBanToggle}
|
||||
handleKanBanToggle={handleKanBanToggle}
|
||||
enableQuickIssueCreate={enableQuickIssueCreate}
|
||||
states={states}
|
||||
labels={labels}
|
||||
members={members}
|
||||
|
|
@ -211,6 +226,7 @@ export const KanBan: React.FC<IKanBan> = observer((props) => {
|
|||
display_properties={display_properties}
|
||||
kanBanToggle={kanBanToggle}
|
||||
handleKanBanToggle={handleKanBanToggle}
|
||||
enableQuickIssueCreate={enableQuickIssueCreate}
|
||||
states={states}
|
||||
labels={labels}
|
||||
members={members}
|
||||
|
|
@ -233,6 +249,7 @@ export const KanBan: React.FC<IKanBan> = observer((props) => {
|
|||
display_properties={display_properties}
|
||||
kanBanToggle={kanBanToggle}
|
||||
handleKanBanToggle={handleKanBanToggle}
|
||||
enableQuickIssueCreate={enableQuickIssueCreate}
|
||||
states={states}
|
||||
labels={labels}
|
||||
members={members}
|
||||
|
|
@ -255,6 +272,7 @@ export const KanBan: React.FC<IKanBan> = observer((props) => {
|
|||
display_properties={display_properties}
|
||||
kanBanToggle={kanBanToggle}
|
||||
handleKanBanToggle={handleKanBanToggle}
|
||||
enableQuickIssueCreate={enableQuickIssueCreate}
|
||||
states={states}
|
||||
labels={labels}
|
||||
members={members}
|
||||
|
|
@ -277,6 +295,7 @@ export const KanBan: React.FC<IKanBan> = observer((props) => {
|
|||
display_properties={display_properties}
|
||||
kanBanToggle={kanBanToggle}
|
||||
handleKanBanToggle={handleKanBanToggle}
|
||||
enableQuickIssueCreate={enableQuickIssueCreate}
|
||||
states={states}
|
||||
labels={labels}
|
||||
members={members}
|
||||
|
|
@ -299,6 +318,7 @@ export const KanBan: React.FC<IKanBan> = observer((props) => {
|
|||
display_properties={display_properties}
|
||||
kanBanToggle={kanBanToggle}
|
||||
handleKanBanToggle={handleKanBanToggle}
|
||||
enableQuickIssueCreate={enableQuickIssueCreate}
|
||||
states={states}
|
||||
labels={labels}
|
||||
members={members}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
export * from "./block";
|
||||
export * from "./roots";
|
||||
export * from "./blocks-list";
|
||||
export * from "./inline-create-issue-form";
|
||||
|
|
|
|||
|
|
@ -0,0 +1,202 @@
|
|||
import { useEffect, useState, useRef } from "react";
|
||||
import { useRouter } from "next/router";
|
||||
import { useForm } from "react-hook-form";
|
||||
import { Transition } from "@headlessui/react";
|
||||
import { PlusIcon } from "lucide-react";
|
||||
// store
|
||||
import { observer } from "mobx-react-lite";
|
||||
import { useMobxStore } from "lib/mobx/store-provider";
|
||||
|
||||
// hooks
|
||||
import useToast from "hooks/use-toast";
|
||||
import useKeypress from "hooks/use-keypress";
|
||||
import useProjectDetails from "hooks/use-project-details";
|
||||
import useOutsideClickDetector from "hooks/use-outside-click-detector";
|
||||
|
||||
// constants
|
||||
import { createIssuePayload } from "constants/issue";
|
||||
|
||||
// types
|
||||
import { IIssue } from "types";
|
||||
|
||||
type Props = {
|
||||
groupId?: string;
|
||||
subGroupId?: string;
|
||||
prePopulatedData?: Partial<IIssue>;
|
||||
onSuccess?: (data: IIssue) => Promise<void> | void;
|
||||
};
|
||||
|
||||
const defaultValues: Partial<IIssue> = {
|
||||
name: "",
|
||||
};
|
||||
|
||||
const Inputs = (props: any) => {
|
||||
const { register, setFocus, projectDetails } = props;
|
||||
|
||||
useEffect(() => {
|
||||
setFocus("name");
|
||||
}, [setFocus]);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h4 className="text-sm font-medium leading-5 text-custom-text-300">{projectDetails?.identifier ?? "..."}</h4>
|
||||
<input
|
||||
autoComplete="off"
|
||||
placeholder="Issue Title"
|
||||
{...register("name", {
|
||||
required: "Issue title is required.",
|
||||
})}
|
||||
className="w-full px-2 pl-0 py-1.5 rounded-md bg-transparent text-sm font-medium leading-5 text-custom-text-200 outline-none"
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export const BoardInlineCreateIssueForm: React.FC<Props> = observer((props) => {
|
||||
const { prePopulatedData, groupId, subGroupId } = props;
|
||||
|
||||
// router
|
||||
const router = useRouter();
|
||||
const { workspaceSlug, projectId } = router.query;
|
||||
|
||||
// store
|
||||
const { workspace: workspaceStore, quickAddIssue: quickAddStore } = useMobxStore();
|
||||
|
||||
// ref
|
||||
const ref = useRef<HTMLFormElement>(null);
|
||||
|
||||
// states
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
|
||||
const { setToastAlert } = useToast();
|
||||
|
||||
const { projectDetails } = useProjectDetails();
|
||||
|
||||
const {
|
||||
reset,
|
||||
handleSubmit,
|
||||
register,
|
||||
setFocus,
|
||||
formState: { errors, isSubmitting },
|
||||
} = useForm<IIssue>({ defaultValues });
|
||||
|
||||
const handleClose = () => {
|
||||
setIsOpen(false);
|
||||
};
|
||||
|
||||
useKeypress("Escape", handleClose);
|
||||
useOutsideClickDetector(ref, handleClose);
|
||||
|
||||
// derived values
|
||||
const workspaceDetail = workspaceStore.getWorkspaceBySlug(workspaceSlug?.toString()!);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isOpen) reset({ ...defaultValues });
|
||||
}, [isOpen, reset]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!errors) return;
|
||||
|
||||
Object.keys(errors).forEach((key) => {
|
||||
const error = errors[key as keyof IIssue];
|
||||
|
||||
setToastAlert({
|
||||
type: "error",
|
||||
title: "Error!",
|
||||
message: error?.message?.toString() || "Some error occurred. Please try again.",
|
||||
});
|
||||
});
|
||||
}, [errors, setToastAlert]);
|
||||
|
||||
const onSubmitHandler = async (formData: IIssue) => {
|
||||
if (isSubmitting || !workspaceSlug || !projectId) return;
|
||||
|
||||
// resetting the form so that user can add another issue quickly
|
||||
reset({ ...defaultValues, ...(prePopulatedData ?? {}) });
|
||||
|
||||
const payload = createIssuePayload(workspaceDetail!, projectDetails!, {
|
||||
...(prePopulatedData ?? {}),
|
||||
...formData,
|
||||
labels_list:
|
||||
formData.labels_list && formData.labels_list.length !== 0
|
||||
? formData.labels_list
|
||||
: prePopulatedData?.labels && prePopulatedData?.labels.toString() !== "none"
|
||||
? [prePopulatedData.labels as any]
|
||||
: [],
|
||||
assignees_list:
|
||||
formData.assignees_list && formData.assignees_list.length !== 0
|
||||
? formData.assignees_list
|
||||
: prePopulatedData?.assignees && prePopulatedData?.assignees.toString() !== "none"
|
||||
? [prePopulatedData.assignees as any]
|
||||
: [],
|
||||
});
|
||||
|
||||
try {
|
||||
quickAddStore.createIssue(
|
||||
workspaceSlug.toString(),
|
||||
projectId.toString(),
|
||||
{
|
||||
group_id: groupId ?? null,
|
||||
sub_group_id: subGroupId ?? null,
|
||||
},
|
||||
payload
|
||||
);
|
||||
|
||||
setToastAlert({
|
||||
type: "success",
|
||||
title: "Success!",
|
||||
message: "Issue created successfully.",
|
||||
});
|
||||
} catch (err: any) {
|
||||
Object.keys(err || {}).forEach((key) => {
|
||||
const error = err?.[key];
|
||||
const errorTitle = error ? (Array.isArray(error) ? error.join(", ") : error) : null;
|
||||
|
||||
setToastAlert({
|
||||
type: "error",
|
||||
title: "Error!",
|
||||
message: errorTitle || "Some error occurred. Please try again.",
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Transition
|
||||
show={isOpen}
|
||||
enter="transition ease-in-out duration-200 transform"
|
||||
enterFrom="opacity-0 scale-95"
|
||||
enterTo="opacity-100 scale-100"
|
||||
leave="transition ease-in-out duration-200 transform"
|
||||
leaveFrom="opacity-100 scale-100"
|
||||
leaveTo="opacity-0 scale-95"
|
||||
>
|
||||
<form
|
||||
ref={ref}
|
||||
onSubmit={handleSubmit(onSubmitHandler)}
|
||||
className="flex flex-col border-[0.5px] border-custom-border-100 justify-between gap-1.5 group/card relative select-none px-3.5 py-3 h-[118px] mb-3 rounded bg-custom-background-100 shadow-custom-shadow-sm"
|
||||
>
|
||||
<Inputs register={register} setFocus={setFocus} projectDetails={projectDetails} />
|
||||
</form>
|
||||
</Transition>
|
||||
|
||||
{isOpen && (
|
||||
<p className="text-xs ml-3 italic text-custom-text-200">
|
||||
Press {"'"}Enter{"'"} to add another issue
|
||||
</p>
|
||||
)}
|
||||
|
||||
{!isOpen && (
|
||||
<button
|
||||
type="button"
|
||||
className="flex items-center gap-x-[6px] text-custom-primary-100 px-2 py-1 rounded-md"
|
||||
onClick={() => setIsOpen(true)}
|
||||
>
|
||||
<PlusIcon className="h-4 w-4" />
|
||||
<span className="text-sm font-medium text-custom-primary-100">New Issue</span>
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
});
|
||||
|
|
@ -112,6 +112,7 @@ export const KanBanLayout: React.FC = observer(() => {
|
|||
labels={labels}
|
||||
members={members?.map((m) => m.member) ?? null}
|
||||
projects={projects}
|
||||
enableQuickIssueCreate
|
||||
estimates={estimates?.points ? orderArrayBy(estimates.points, "key") : null}
|
||||
/>
|
||||
) : (
|
||||
|
|
|
|||
|
|
@ -153,6 +153,7 @@ const SubGroupSwimlane: React.FC<ISubGroupSwimlane> = observer((props) => {
|
|||
members={members}
|
||||
projects={projects}
|
||||
estimates={estimates}
|
||||
enableQuickIssueCreate
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
|
|
|||
|
|
@ -27,12 +27,15 @@ export const IssueBlock: React.FC<IssueBlockProps> = (props) => {
|
|||
|
||||
return (
|
||||
<>
|
||||
<div className="text-sm p-3 shadow-custom-shadow-2xs bg-custom-background-100 flex items-center gap-3 border-b border-custom-border-200 hover:bg-custom-background-80">
|
||||
<div className="text-sm p-3 relative shadow-custom-shadow-2xs bg-custom-background-100 flex items-center gap-3 border-b border-custom-border-200 hover:bg-custom-background-80">
|
||||
{display_properties && display_properties?.key && (
|
||||
<div className="flex-shrink-0 text-xs text-custom-text-300">
|
||||
{issue?.project_detail?.identifier}-{issue.sequence_id}
|
||||
</div>
|
||||
)}
|
||||
{issue?.tempId !== undefined && (
|
||||
<div className="absolute top-0 left-0 w-full h-full animate-pulse bg-custom-background-100/20 z-[99999]" />
|
||||
)}
|
||||
<IssuePeekOverview
|
||||
workspaceSlug={issue?.workspace_detail?.slug}
|
||||
projectId={issue?.project_detail?.id}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import React from "react";
|
|||
import { observer } from "mobx-react-lite";
|
||||
// components
|
||||
import { ListGroupByHeaderRoot } from "./headers/group-by-root";
|
||||
import { IssueBlocksList } from "components/issues";
|
||||
import { IssueBlocksList, ListInlineCreateIssueForm } from "components/issues";
|
||||
// types
|
||||
import { IEstimatePoint, IIssue, IIssueLabels, IProject, IState, IUserLite } from "types";
|
||||
// constants
|
||||
|
|
@ -23,6 +23,7 @@ export interface IGroupByList {
|
|||
projects: IProject[] | null;
|
||||
stateGroups: any;
|
||||
priorities: any;
|
||||
enableQuickIssueCreate?: boolean;
|
||||
estimates: IEstimatePoint[] | null;
|
||||
}
|
||||
|
||||
|
|
@ -43,6 +44,7 @@ const GroupByList: React.FC<IGroupByList> = observer((props) => {
|
|||
stateGroups,
|
||||
priorities,
|
||||
estimates,
|
||||
enableQuickIssueCreate,
|
||||
} = props;
|
||||
|
||||
return (
|
||||
|
|
@ -76,6 +78,14 @@ const GroupByList: React.FC<IGroupByList> = observer((props) => {
|
|||
/>
|
||||
)}
|
||||
</div>
|
||||
{enableQuickIssueCreate && (
|
||||
<ListInlineCreateIssueForm
|
||||
groupId={getValueFromObject(_list, listKey) as string}
|
||||
prePopulatedData={{
|
||||
[group_by!]: getValueFromObject(_list, listKey),
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
|
@ -96,6 +106,7 @@ export interface IList {
|
|||
projects: IProject[] | null;
|
||||
stateGroups: any;
|
||||
priorities: any;
|
||||
enableQuickIssueCreate?: boolean;
|
||||
estimates: IEstimatePoint[] | null;
|
||||
}
|
||||
|
||||
|
|
@ -113,6 +124,7 @@ export const List: React.FC<IList> = observer((props) => {
|
|||
stateGroups,
|
||||
priorities,
|
||||
estimates,
|
||||
enableQuickIssueCreate,
|
||||
} = props;
|
||||
|
||||
return (
|
||||
|
|
@ -134,6 +146,7 @@ export const List: React.FC<IList> = observer((props) => {
|
|||
stateGroups={stateGroups}
|
||||
priorities={priorities}
|
||||
estimates={estimates}
|
||||
enableQuickIssueCreate={enableQuickIssueCreate}
|
||||
/>
|
||||
)}
|
||||
|
||||
|
|
@ -153,6 +166,7 @@ export const List: React.FC<IList> = observer((props) => {
|
|||
stateGroups={stateGroups}
|
||||
priorities={priorities}
|
||||
estimates={estimates}
|
||||
enableQuickIssueCreate={enableQuickIssueCreate}
|
||||
/>
|
||||
)}
|
||||
|
||||
|
|
@ -172,6 +186,7 @@ export const List: React.FC<IList> = observer((props) => {
|
|||
stateGroups={stateGroups}
|
||||
priorities={priorities}
|
||||
estimates={estimates}
|
||||
enableQuickIssueCreate={enableQuickIssueCreate}
|
||||
/>
|
||||
)}
|
||||
|
||||
|
|
@ -191,6 +206,7 @@ export const List: React.FC<IList> = observer((props) => {
|
|||
stateGroups={stateGroups}
|
||||
priorities={priorities}
|
||||
estimates={estimates}
|
||||
enableQuickIssueCreate={enableQuickIssueCreate}
|
||||
/>
|
||||
)}
|
||||
|
||||
|
|
@ -210,6 +226,7 @@ export const List: React.FC<IList> = observer((props) => {
|
|||
stateGroups={stateGroups}
|
||||
priorities={priorities}
|
||||
estimates={estimates}
|
||||
enableQuickIssueCreate={enableQuickIssueCreate}
|
||||
/>
|
||||
)}
|
||||
|
||||
|
|
@ -229,6 +246,7 @@ export const List: React.FC<IList> = observer((props) => {
|
|||
stateGroups={stateGroups}
|
||||
priorities={priorities}
|
||||
estimates={estimates}
|
||||
enableQuickIssueCreate={enableQuickIssueCreate}
|
||||
/>
|
||||
)}
|
||||
|
||||
|
|
@ -248,6 +266,7 @@ export const List: React.FC<IList> = observer((props) => {
|
|||
stateGroups={stateGroups}
|
||||
priorities={priorities}
|
||||
estimates={estimates}
|
||||
enableQuickIssueCreate={enableQuickIssueCreate}
|
||||
/>
|
||||
)}
|
||||
|
||||
|
|
@ -267,6 +286,7 @@ export const List: React.FC<IList> = observer((props) => {
|
|||
stateGroups={stateGroups}
|
||||
priorities={priorities}
|
||||
estimates={estimates}
|
||||
enableQuickIssueCreate={enableQuickIssueCreate}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
export * from "./roots";
|
||||
export * from "./block";
|
||||
export * from "./blocks-list";
|
||||
export * from "./inline-create-issue-form";
|
||||
|
|
|
|||
|
|
@ -0,0 +1,201 @@
|
|||
import { useEffect, useState, useRef } from "react";
|
||||
import { useRouter } from "next/router";
|
||||
import { useForm } from "react-hook-form";
|
||||
import { Transition } from "@headlessui/react";
|
||||
|
||||
// hooks
|
||||
import useToast from "hooks/use-toast";
|
||||
import useKeypress from "hooks/use-keypress";
|
||||
import useProjectDetails from "hooks/use-project-details";
|
||||
import useOutsideClickDetector from "hooks/use-outside-click-detector";
|
||||
|
||||
// store
|
||||
import { observer } from "mobx-react-lite";
|
||||
import { useMobxStore } from "lib/mobx/store-provider";
|
||||
|
||||
// constants
|
||||
import { createIssuePayload } from "constants/issue";
|
||||
|
||||
// types
|
||||
import { IIssue } from "types";
|
||||
import { PlusIcon } from "lucide-react";
|
||||
|
||||
type Props = {
|
||||
groupId?: string;
|
||||
prePopulatedData?: Partial<IIssue>;
|
||||
onSuccess?: (data: IIssue) => Promise<void> | void;
|
||||
};
|
||||
|
||||
const defaultValues: Partial<IIssue> = {
|
||||
name: "",
|
||||
};
|
||||
|
||||
const Inputs = (props: any) => {
|
||||
const { register, setFocus, projectDetails } = props;
|
||||
|
||||
useEffect(() => {
|
||||
setFocus("name");
|
||||
}, [setFocus]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<h4 className="text-sm font-medium leading-5 text-custom-text-400">{projectDetails?.identifier ?? "..."}</h4>
|
||||
<input
|
||||
type="text"
|
||||
autoComplete="off"
|
||||
placeholder="Issue Title"
|
||||
{...register("name", {
|
||||
required: "Issue title is required.",
|
||||
})}
|
||||
className="w-full px-2 py-3 rounded-md bg-transparent text-sm font-medium leading-5 text-custom-text-200 outline-none"
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export const ListInlineCreateIssueForm: React.FC<Props> = observer((props) => {
|
||||
const { prePopulatedData, groupId } = props;
|
||||
|
||||
// router
|
||||
const router = useRouter();
|
||||
const { workspaceSlug, projectId } = router.query;
|
||||
|
||||
// store
|
||||
const { workspace: workspaceStore, quickAddIssue: quickAddStore } = useMobxStore();
|
||||
|
||||
const { projectDetails } = useProjectDetails();
|
||||
|
||||
const {
|
||||
reset,
|
||||
handleSubmit,
|
||||
setFocus,
|
||||
register,
|
||||
formState: { errors, isSubmitting },
|
||||
} = useForm<IIssue>({ defaultValues });
|
||||
|
||||
// ref
|
||||
const ref = useRef<HTMLFormElement>(null);
|
||||
|
||||
// states
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
|
||||
const handleClose = () => setIsOpen(false);
|
||||
|
||||
// hooks
|
||||
useKeypress("Escape", handleClose);
|
||||
useOutsideClickDetector(ref, handleClose);
|
||||
const { setToastAlert } = useToast();
|
||||
|
||||
// derived values
|
||||
const workspaceDetail = workspaceStore.getWorkspaceBySlug(workspaceSlug?.toString()!);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isOpen) reset({ ...defaultValues });
|
||||
}, [isOpen, reset]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!errors) return;
|
||||
|
||||
Object.keys(errors).forEach((key) => {
|
||||
const error = errors[key as keyof IIssue];
|
||||
|
||||
setToastAlert({
|
||||
type: "error",
|
||||
title: "Error!",
|
||||
message: error?.message?.toString() || "Some error occurred. Please try again.",
|
||||
});
|
||||
});
|
||||
}, [errors, setToastAlert]);
|
||||
|
||||
const onSubmitHandler = async (formData: IIssue) => {
|
||||
if (isSubmitting || !workspaceSlug || !projectId) return;
|
||||
|
||||
// resetting the form so that user can add another issue quickly
|
||||
reset({ ...defaultValues });
|
||||
|
||||
const payload = createIssuePayload(workspaceDetail!, projectDetails!, {
|
||||
...(prePopulatedData ?? {}),
|
||||
...formData,
|
||||
labels_list:
|
||||
formData.labels_list?.length !== 0
|
||||
? formData.labels_list
|
||||
: prePopulatedData?.labels && prePopulatedData?.labels.toString() !== "none"
|
||||
? [prePopulatedData.labels as any]
|
||||
: [],
|
||||
assignees_list:
|
||||
formData.assignees_list?.length !== 0
|
||||
? formData.assignees_list
|
||||
: prePopulatedData?.assignees && prePopulatedData?.assignees.toString() !== "none"
|
||||
? [prePopulatedData.assignees as any]
|
||||
: [],
|
||||
});
|
||||
|
||||
try {
|
||||
quickAddStore.createIssue(
|
||||
workspaceSlug.toString(),
|
||||
projectId.toString(),
|
||||
{
|
||||
group_id: groupId ?? null,
|
||||
sub_group_id: null,
|
||||
},
|
||||
payload
|
||||
);
|
||||
|
||||
setToastAlert({
|
||||
type: "success",
|
||||
title: "Success!",
|
||||
message: "Issue created successfully.",
|
||||
});
|
||||
} catch (err: any) {
|
||||
Object.keys(err || {}).forEach((key) => {
|
||||
const error = err?.[key];
|
||||
const errorTitle = error ? (Array.isArray(error) ? error.join(", ") : error) : null;
|
||||
|
||||
setToastAlert({
|
||||
type: "error",
|
||||
title: "Error!",
|
||||
message: errorTitle || "Some error occurred. Please try again.",
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Transition
|
||||
show={isOpen}
|
||||
enter="transition ease-in-out duration-200 transform"
|
||||
enterFrom="opacity-0 scale-95"
|
||||
enterTo="opacity-100 scale-100"
|
||||
leave="transition ease-in-out duration-200 transform"
|
||||
leaveFrom="opacity-100 scale-100"
|
||||
leaveTo="opacity-0 scale-95"
|
||||
>
|
||||
<form
|
||||
ref={ref}
|
||||
onSubmit={handleSubmit(onSubmitHandler)}
|
||||
className="flex border-[0.5px] border-t-0 border-custom-border-100 px-4 items-center gap-x-5 bg-custom-background-100 shadow-custom-shadow-sm z-10"
|
||||
>
|
||||
<Inputs register={register} setFocus={setFocus} projectDetails={projectDetails} />
|
||||
</form>
|
||||
</Transition>
|
||||
|
||||
{isOpen && (
|
||||
<p className="text-xs ml-3 mt-3 italic text-custom-text-200">
|
||||
Press {"'"}Enter{"'"} to add another issue
|
||||
</p>
|
||||
)}
|
||||
|
||||
{!isOpen && (
|
||||
<button
|
||||
type="button"
|
||||
className="flex items-center gap-x-[6px] text-custom-primary-100 px-2 py-1 rounded-md"
|
||||
onClick={() => setIsOpen(true)}
|
||||
>
|
||||
<PlusIcon className="h-4 w-4" />
|
||||
<span className="text-sm font-medium text-custom-primary-100">New Issue</span>
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
});
|
||||
|
|
@ -76,6 +76,7 @@ export const ListLayout: FC = observer(() => {
|
|||
labels={labels}
|
||||
members={members?.map((m) => m.member) ?? null}
|
||||
projects={projects}
|
||||
enableQuickIssueCreate
|
||||
estimates={estimates?.points ? orderArrayBy(estimates.points, "key") : null}
|
||||
/>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -2,3 +2,4 @@ export * from "./columns";
|
|||
export * from "./roots";
|
||||
export * from "./spreadsheet-column";
|
||||
export * from "./spreadsheet-view";
|
||||
export * from "./inline-create-issue-form";
|
||||
|
|
|
|||
|
|
@ -0,0 +1,207 @@
|
|||
import { useEffect, useState, useRef } from "react";
|
||||
import { useRouter } from "next/router";
|
||||
import { useForm } from "react-hook-form";
|
||||
import { Transition } from "@headlessui/react";
|
||||
|
||||
// hooks
|
||||
import useToast from "hooks/use-toast";
|
||||
import useKeypress from "hooks/use-keypress";
|
||||
import useProjectDetails from "hooks/use-project-details";
|
||||
import useOutsideClickDetector from "hooks/use-outside-click-detector";
|
||||
|
||||
// store
|
||||
import { observer } from "mobx-react-lite";
|
||||
import { useMobxStore } from "lib/mobx/store-provider";
|
||||
|
||||
// constants
|
||||
import { createIssuePayload } from "constants/issue";
|
||||
|
||||
// types
|
||||
import { IIssue } from "types";
|
||||
import { PlusIcon } from "lucide-react";
|
||||
|
||||
type Props = {
|
||||
groupId?: string;
|
||||
prePopulatedData?: Partial<IIssue>;
|
||||
onSuccess?: (data: IIssue) => Promise<void> | void;
|
||||
};
|
||||
|
||||
const defaultValues: Partial<IIssue> = {
|
||||
name: "",
|
||||
};
|
||||
|
||||
const Inputs = (props: any) => {
|
||||
const { register, setFocus, projectDetails } = props;
|
||||
|
||||
useEffect(() => {
|
||||
setFocus("name");
|
||||
}, [setFocus]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<h4 className="text-sm font-medium leading-5 text-custom-text-400">{projectDetails?.identifier ?? "..."}</h4>
|
||||
<input
|
||||
type="text"
|
||||
autoComplete="off"
|
||||
placeholder="Issue Title"
|
||||
{...register("name", {
|
||||
required: "Issue title is required.",
|
||||
})}
|
||||
className="w-full px-2 py-3 rounded-md bg-transparent text-sm font-medium leading-5 text-custom-text-200 outline-none"
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export const SpreadsheetInlineCreateIssueForm: React.FC<Props> = observer((props) => {
|
||||
const { prePopulatedData, groupId } = props;
|
||||
|
||||
// router
|
||||
const router = useRouter();
|
||||
const { workspaceSlug, projectId } = router.query;
|
||||
|
||||
// store
|
||||
const { workspace: workspaceStore, quickAddIssue: quickAddStore } = useMobxStore();
|
||||
|
||||
const { projectDetails } = useProjectDetails();
|
||||
|
||||
const {
|
||||
reset,
|
||||
handleSubmit,
|
||||
setFocus,
|
||||
register,
|
||||
formState: { errors, isSubmitting },
|
||||
} = useForm<IIssue>({ defaultValues });
|
||||
|
||||
// ref
|
||||
const ref = useRef<HTMLFormElement>(null);
|
||||
|
||||
// states
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
|
||||
const handleClose = () => setIsOpen(false);
|
||||
|
||||
// hooks
|
||||
useKeypress("Escape", handleClose);
|
||||
useOutsideClickDetector(ref, handleClose);
|
||||
const { setToastAlert } = useToast();
|
||||
|
||||
// derived values
|
||||
const workspaceDetail = workspaceStore.getWorkspaceBySlug(workspaceSlug?.toString()!);
|
||||
|
||||
useEffect(() => {
|
||||
setFocus("name");
|
||||
}, [setFocus, isOpen]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isOpen) reset({ ...defaultValues });
|
||||
}, [isOpen, reset]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!errors) return;
|
||||
|
||||
Object.keys(errors).forEach((key) => {
|
||||
const error = errors[key as keyof IIssue];
|
||||
|
||||
setToastAlert({
|
||||
type: "error",
|
||||
title: "Error!",
|
||||
message: error?.message?.toString() || "Some error occurred. Please try again.",
|
||||
});
|
||||
});
|
||||
}, [errors, setToastAlert]);
|
||||
|
||||
const onSubmitHandler = async (formData: IIssue) => {
|
||||
if (isSubmitting || !workspaceSlug || !projectId) return;
|
||||
|
||||
// resetting the form so that user can add another issue quickly
|
||||
reset({ ...defaultValues });
|
||||
|
||||
const payload = createIssuePayload(workspaceDetail!, projectDetails!, {
|
||||
...(prePopulatedData ?? {}),
|
||||
...formData,
|
||||
labels_list:
|
||||
formData.labels_list && formData.labels_list?.length !== 0
|
||||
? formData.labels_list
|
||||
: prePopulatedData?.labels && prePopulatedData?.labels.toString() !== "none"
|
||||
? [prePopulatedData.labels as any]
|
||||
: [],
|
||||
assignees_list:
|
||||
formData.assignees_list && formData.assignees_list?.length !== 0
|
||||
? formData.assignees_list
|
||||
: prePopulatedData?.assignees && prePopulatedData?.assignees.toString() !== "none"
|
||||
? [prePopulatedData.assignees as any]
|
||||
: [],
|
||||
});
|
||||
|
||||
try {
|
||||
quickAddStore.createIssue(
|
||||
workspaceSlug.toString(),
|
||||
projectId.toString(),
|
||||
{
|
||||
group_id: groupId ?? null,
|
||||
sub_group_id: null,
|
||||
},
|
||||
payload
|
||||
);
|
||||
|
||||
setToastAlert({
|
||||
type: "success",
|
||||
title: "Success!",
|
||||
message: "Issue created successfully.",
|
||||
});
|
||||
} catch (err: any) {
|
||||
Object.keys(err || {}).forEach((key) => {
|
||||
const error = err?.[key];
|
||||
const errorTitle = error ? (Array.isArray(error) ? error.join(", ") : error) : null;
|
||||
|
||||
setToastAlert({
|
||||
type: "error",
|
||||
title: "Error!",
|
||||
message: errorTitle || "Some error occurred. Please try again.",
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Transition
|
||||
show={isOpen}
|
||||
enter="transition ease-in-out duration-200 transform"
|
||||
enterFrom="opacity-0 scale-95"
|
||||
enterTo="opacity-100 scale-100"
|
||||
leave="transition ease-in-out duration-200 transform"
|
||||
leaveFrom="opacity-100 scale-100"
|
||||
leaveTo="opacity-0 scale-95"
|
||||
>
|
||||
<div>
|
||||
<form
|
||||
ref={ref}
|
||||
onSubmit={handleSubmit(onSubmitHandler)}
|
||||
className="flex border-[0.5px] border-t-0 border-custom-border-100 px-4 items-center gap-x-5 bg-custom-background-100 shadow-custom-shadow-sm z-10"
|
||||
>
|
||||
<Inputs register={register} setFocus={setFocus} projectDetails={projectDetails} />
|
||||
</form>
|
||||
</div>
|
||||
</Transition>
|
||||
|
||||
{isOpen && (
|
||||
<p className="text-xs ml-3 mt-3 italic text-custom-text-200">
|
||||
Press {"'"}Enter{"'"} to add another issue
|
||||
</p>
|
||||
)}
|
||||
|
||||
{!isOpen && (
|
||||
<button
|
||||
type="button"
|
||||
className="flex items-center gap-x-[6px] text-custom-primary-100 px-2 py-1 rounded-md"
|
||||
onClick={() => setIsOpen(true)}
|
||||
>
|
||||
<PlusIcon className="h-4 w-4" />
|
||||
<span className="text-sm font-medium text-custom-primary-100">New Issue</span>
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
});
|
||||
|
|
@ -66,6 +66,7 @@ export const ProjectSpreadsheetLayout: React.FC = observer(() => {
|
|||
handleIssueAction={() => {}}
|
||||
handleUpdateIssue={handleUpdateIssue}
|
||||
disableUserActions={false}
|
||||
enableQuickCreateIssue
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -3,11 +3,7 @@ import { useRouter } from "next/router";
|
|||
import { observer } from "mobx-react-lite";
|
||||
import { PlusIcon } from "lucide-react";
|
||||
// components
|
||||
import {
|
||||
SpreadsheetColumnsList,
|
||||
// ListInlineCreateIssueForm,
|
||||
SpreadsheetIssuesColumn,
|
||||
} from "components/issues";
|
||||
import { SpreadsheetColumnsList, SpreadsheetIssuesColumn, SpreadsheetInlineCreateIssueForm } from "components/issues";
|
||||
import { CustomMenu, Spinner } from "@plane/ui";
|
||||
// types
|
||||
import {
|
||||
|
|
@ -31,6 +27,7 @@ type Props = {
|
|||
handleUpdateIssue: (issue: IIssue, data: Partial<IIssue>) => void;
|
||||
openIssuesListModal?: (() => void) | null;
|
||||
disableUserActions: boolean;
|
||||
enableQuickCreateIssue?: boolean;
|
||||
};
|
||||
|
||||
export const SpreadsheetView: React.FC<Props> = observer((props) => {
|
||||
|
|
@ -46,6 +43,7 @@ export const SpreadsheetView: React.FC<Props> = observer((props) => {
|
|||
handleUpdateIssue,
|
||||
openIssuesListModal,
|
||||
disableUserActions,
|
||||
enableQuickCreateIssue,
|
||||
} = props;
|
||||
|
||||
const [expandedIssues, setExpandedIssues] = useState<string[]>([]);
|
||||
|
|
@ -138,17 +136,10 @@ export const SpreadsheetView: React.FC<Props> = observer((props) => {
|
|||
|
||||
<div className="border-t border-custom-border-100">
|
||||
<div className="mb-3 z-50 sticky bottom-0 left-0">
|
||||
{/* <ListInlineCreateIssueForm
|
||||
isOpen={isInlineCreateIssueFormOpen}
|
||||
handleClose={() => setIsInlineCreateIssueFormOpen(false)}
|
||||
prePopulatedData={{
|
||||
...(cycleId && { cycle: cycleId.toString() }),
|
||||
...(moduleId && { module: moduleId.toString() }),
|
||||
}}
|
||||
/> */}
|
||||
{enableQuickCreateIssue && <SpreadsheetInlineCreateIssueForm />}
|
||||
</div>
|
||||
|
||||
{!disableUserActions &&
|
||||
{/* {!disableUserActions &&
|
||||
!isInlineCreateIssueFormOpen &&
|
||||
(type === "issue" ? (
|
||||
<button
|
||||
|
|
@ -180,7 +171,7 @@ export const SpreadsheetView: React.FC<Props> = observer((props) => {
|
|||
<CustomMenu.MenuItem onClick={openIssuesListModal}>Add an existing issue</CustomMenu.MenuItem>
|
||||
)}
|
||||
</CustomMenu>
|
||||
))}
|
||||
))} */}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue