forked from github/plane
53367a6bc4
* new toast setup * chore: new toast implementation. * chore: move toast component to ui package. * chore: replace `setToast` with `setPromiseToast` in required places for better UX. * chore: code cleanup. * chore: update theme. * fix: theme switching issue. * chore: remove toast from issue update operations. * chore: add promise toast for add/ remove issue to cycle/ module and remove local spinners. --------- Co-authored-by: rahulramesha <rahulramesham@gmail.com>
70 lines
2.4 KiB
TypeScript
70 lines
2.4 KiB
TypeScript
import React, { ReactElement } from "react";
|
|
import { useRouter } from "next/router";
|
|
import { observer } from "mobx-react-lite";
|
|
// hooks
|
|
import { useProject, useUser } from "hooks/store";
|
|
// layouts
|
|
import { AppLayout } from "layouts/app-layout";
|
|
import { ProjectSettingLayout } from "layouts/settings-layout";
|
|
// ui
|
|
import { TOAST_TYPE, setToast } from "@plane/ui";
|
|
// components
|
|
import { AutoArchiveAutomation, AutoCloseAutomation } from "components/automation";
|
|
import { PageHead } from "components/core";
|
|
import { ProjectSettingHeader } from "components/headers";
|
|
// types
|
|
import { NextPageWithLayout } from "lib/types";
|
|
import { IProject } from "@plane/types";
|
|
// constants
|
|
import { EUserProjectRoles } from "constants/project";
|
|
|
|
const AutomationSettingsPage: NextPageWithLayout = observer(() => {
|
|
// router
|
|
const router = useRouter();
|
|
const { workspaceSlug, projectId } = router.query;
|
|
// store hooks
|
|
const {
|
|
membership: { currentProjectRole },
|
|
} = useUser();
|
|
const { currentProjectDetails: projectDetails, updateProject } = useProject();
|
|
|
|
const handleChange = async (formData: Partial<IProject>) => {
|
|
if (!workspaceSlug || !projectId || !projectDetails) return;
|
|
|
|
await updateProject(workspaceSlug.toString(), projectId.toString(), formData).catch(() => {
|
|
setToast({
|
|
type: TOAST_TYPE.ERROR,
|
|
title: "Error!",
|
|
message: "Something went wrong. Please try again.",
|
|
});
|
|
});
|
|
};
|
|
|
|
// derived values
|
|
const isAdmin = currentProjectRole === EUserProjectRoles.ADMIN;
|
|
const pageTitle = projectDetails?.name ? `${projectDetails?.name} - Automations` : undefined;
|
|
|
|
return (
|
|
<>
|
|
<PageHead title={pageTitle} />
|
|
<section className={`w-full overflow-y-auto py-8 pr-9 ${isAdmin ? "" : "opacity-60"}`}>
|
|
<div className="flex items-center border-b border-custom-border-100 py-3.5">
|
|
<h3 className="text-xl font-medium">Automations</h3>
|
|
</div>
|
|
<AutoArchiveAutomation handleChange={handleChange} />
|
|
<AutoCloseAutomation handleChange={handleChange} />
|
|
</section>
|
|
</>
|
|
);
|
|
});
|
|
|
|
AutomationSettingsPage.getLayout = function getLayout(page: ReactElement) {
|
|
return (
|
|
<AppLayout header={<ProjectSettingHeader title="Automations Settings" />} withProjectWrapper>
|
|
<ProjectSettingLayout>{page}</ProjectSettingLayout>
|
|
</AppLayout>
|
|
);
|
|
};
|
|
|
|
export default AutomationSettingsPage;
|