Some checks failed
Branch Build CE / Build Setup (push) Has been cancelled
Branch Build CE / Build-Push Admin Docker Image (push) Has been cancelled
Branch Build CE / Build-Push Web Docker Image (push) Has been cancelled
Branch Build CE / Build-Push Space Docker Image (push) Has been cancelled
Branch Build CE / Build-Push Live Collaboration Docker Image (push) Has been cancelled
Branch Build CE / Build-Push API Server Docker Image (push) Has been cancelled
Branch Build CE / Build-Push Proxy Docker Image (push) Has been cancelled
Branch Build CE / Build-Push AIO Docker Image (push) Has been cancelled
Branch Build CE / Upload Build Assets (push) Has been cancelled
Branch Build CE / Build Release (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Codespell / Check for spelling errors (push) Has been cancelled
Sync Repositories / sync_changes (push) Has been cancelled
Synced from upstream: 8853637e981ed7d8a6cff32bd98e7afe20f54362
125 lines
3.7 KiB
TypeScript
125 lines
3.7 KiB
TypeScript
"use client";
|
|
|
|
import type { FC } from "react";
|
|
import { observer } from "mobx-react";
|
|
// types
|
|
import { PROJECT_VIEW_TRACKER_EVENTS } from "@plane/constants";
|
|
import { TOAST_TYPE, setToast } from "@plane/propel/toast";
|
|
import type { IProjectView } from "@plane/types";
|
|
import { EIssuesStoreType } from "@plane/types";
|
|
// ui
|
|
import { EModalPosition, EModalWidth, ModalCore } from "@plane/ui";
|
|
// hooks
|
|
import { captureError, captureSuccess } from "@/helpers/event-tracker.helper";
|
|
import { useIssues } from "@/hooks/store/use-issues";
|
|
import { useProjectView } from "@/hooks/store/use-project-view";
|
|
import { useWorkItemFilters } from "@/hooks/store/work-item-filters/use-work-item-filters";
|
|
import { useAppRouter } from "@/hooks/use-app-router";
|
|
import useKeypress from "@/hooks/use-keypress";
|
|
// local imports
|
|
import { ProjectViewForm } from "./form";
|
|
|
|
type Props = {
|
|
data?: IProjectView | null;
|
|
isOpen: boolean;
|
|
onClose: () => void;
|
|
preLoadedData?: Partial<IProjectView> | null;
|
|
workspaceSlug: string;
|
|
projectId: string;
|
|
};
|
|
|
|
export const CreateUpdateProjectViewModal: FC<Props> = observer((props) => {
|
|
const { data, isOpen, onClose, preLoadedData, workspaceSlug, projectId } = props;
|
|
// router
|
|
const router = useAppRouter();
|
|
// store hooks
|
|
const { createView, updateView } = useProjectView();
|
|
const {
|
|
issuesFilter: { mutateFilters },
|
|
} = useIssues(EIssuesStoreType.PROJECT_VIEW);
|
|
const { resetExpression } = useWorkItemFilters();
|
|
|
|
const handleClose = () => {
|
|
onClose();
|
|
};
|
|
|
|
const handleCreateView = async (payload: IProjectView) => {
|
|
await createView(workspaceSlug, projectId, payload)
|
|
.then((res) => {
|
|
handleClose();
|
|
router.push(`/${workspaceSlug}/projects/${projectId}/views/${res.id}`);
|
|
setToast({
|
|
type: TOAST_TYPE.SUCCESS,
|
|
title: "Success!",
|
|
message: "View created successfully.",
|
|
});
|
|
captureSuccess({
|
|
eventName: PROJECT_VIEW_TRACKER_EVENTS.create,
|
|
payload: {
|
|
view_id: res.id,
|
|
},
|
|
});
|
|
})
|
|
.catch(() => {
|
|
setToast({
|
|
type: TOAST_TYPE.ERROR,
|
|
title: "Error!",
|
|
message: "Something went wrong. Please try again.",
|
|
});
|
|
captureError({
|
|
eventName: PROJECT_VIEW_TRACKER_EVENTS.create,
|
|
});
|
|
});
|
|
};
|
|
|
|
const handleUpdateView = async (payload: IProjectView) => {
|
|
await updateView(workspaceSlug, projectId, data?.id as string, payload)
|
|
.then((viewDetails) => {
|
|
mutateFilters(workspaceSlug, viewDetails.id, viewDetails);
|
|
resetExpression(EIssuesStoreType.PROJECT_VIEW, viewDetails.id, viewDetails.rich_filters);
|
|
handleClose();
|
|
captureSuccess({
|
|
eventName: PROJECT_VIEW_TRACKER_EVENTS.update,
|
|
payload: {
|
|
view_id: data?.id,
|
|
},
|
|
});
|
|
})
|
|
.catch((err) => {
|
|
setToast({
|
|
type: TOAST_TYPE.ERROR,
|
|
title: "Error!",
|
|
message: err?.detail ?? "Something went wrong. Please try again.",
|
|
});
|
|
captureError({
|
|
eventName: PROJECT_VIEW_TRACKER_EVENTS.update,
|
|
payload: {
|
|
view_id: data?.id,
|
|
},
|
|
});
|
|
});
|
|
};
|
|
|
|
const handleFormSubmit = async (formData: IProjectView) => {
|
|
if (!data) await handleCreateView(formData);
|
|
else await handleUpdateView(formData);
|
|
};
|
|
|
|
useKeypress("Escape", () => {
|
|
if (isOpen) handleClose();
|
|
});
|
|
|
|
return (
|
|
<ModalCore isOpen={isOpen} position={EModalPosition.TOP} width={EModalWidth.XXL}>
|
|
<ProjectViewForm
|
|
data={data}
|
|
handleClose={handleClose}
|
|
handleFormSubmit={handleFormSubmit}
|
|
preLoadedData={preLoadedData}
|
|
projectId={projectId}
|
|
workspaceSlug={workspaceSlug}
|
|
/>
|
|
</ModalCore>
|
|
);
|
|
});
|