Some checks failed
CodeQL / Analyze (javascript) (push) Failing after 16s
CodeQL / Analyze (python) (push) Failing after 3s
i18n sync check / check:sync (push) Failing after 3s
React Doctor / react-doctor (push) Failing after 16s
Branch Build CE / Build-Push Admin Docker Image (${{ matrix.arch }}) (push) Has been cancelled
Branch Build CE / Merge Admin Manifest (push) Has been cancelled
Branch Build CE / Build-Push Web Docker Image (${{ matrix.arch }}) (push) Has been cancelled
Branch Build CE / Merge Web Manifest (push) Has been cancelled
Branch Build CE / Build-Push Space Docker Image (${{ matrix.arch }}) (push) Has been cancelled
Branch Build CE / Merge Proxy Manifest (push) Has been cancelled
Branch Build CE / Merge Space Manifest (push) Has been cancelled
Branch Build CE / Prepare AIO Assets (push) Has been cancelled
Branch Build CE / Build Setup (push) Has been cancelled
Branch Build CE / Build-Push Live Collaboration Docker Image (${{ matrix.arch }}) (push) Has been cancelled
Branch Build CE / Merge Live Collaboration Manifest (push) Has been cancelled
Branch Build CE / Build-Push API Server Docker Image (${{ matrix.arch }}) (push) Has been cancelled
Branch Build CE / Merge API Server Manifest (push) Has been cancelled
Branch Build CE / Build-Push Proxy Docker Image (${{ matrix.arch }}) (push) Has been cancelled
Branch Build CE / Build-Push AIO Docker Image (${{ matrix.arch }}) (push) Has been cancelled
Branch Build CE / Merge AIO Manifest (push) Has been cancelled
Branch Build CE / Upload Build Assets (push) Has been cancelled
Branch Build CE / Build Release (push) Has been cancelled
103 lines
3.1 KiB
TypeScript
103 lines
3.1 KiB
TypeScript
/**
|
|
* Copyright (c) 2023-present Plane Software, Inc. and contributors
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
* See the LICENSE file for details.
|
|
*/
|
|
|
|
import { observer } from "mobx-react";
|
|
// types
|
|
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 { 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 = observer(function CreateUpdateProjectViewModal(props: 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) => {
|
|
try {
|
|
const res = await createView(workspaceSlug, projectId, payload);
|
|
handleClose();
|
|
router.push(`/${workspaceSlug}/projects/${projectId}/views/${res.id}`);
|
|
setToast({
|
|
type: TOAST_TYPE.SUCCESS,
|
|
title: "Success!",
|
|
message: "View created successfully.",
|
|
});
|
|
} catch (_error) {
|
|
setToast({
|
|
type: TOAST_TYPE.ERROR,
|
|
title: "Error!",
|
|
message: "Failed to create view. Please try again.",
|
|
});
|
|
}
|
|
};
|
|
|
|
const handleUpdateView = async (payload: IProjectView) => {
|
|
try {
|
|
const viewDetails = await updateView(workspaceSlug, projectId, data?.id as string, payload);
|
|
mutateFilters(workspaceSlug, viewDetails.id, viewDetails);
|
|
resetExpression(EIssuesStoreType.PROJECT_VIEW, viewDetails.id, viewDetails.rich_filters);
|
|
handleClose();
|
|
} catch (_error) {
|
|
setToast({
|
|
type: TOAST_TYPE.ERROR,
|
|
title: "Error!",
|
|
message: "Failed to update view. Please try again.",
|
|
});
|
|
}
|
|
};
|
|
|
|
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>
|
|
);
|
|
});
|