2023-11-02 18:27:44 +00:00
|
|
|
import React, { ReactElement } from "react";
|
2023-07-13 06:04:37 +00:00
|
|
|
import { useRouter } from "next/router";
|
2023-11-14 13:03:01 +00:00
|
|
|
import { observer } from "mobx-react-lite";
|
|
|
|
// store
|
|
|
|
import { useMobxStore } from "lib/mobx/store-provider";
|
2023-07-13 06:04:37 +00:00
|
|
|
// layouts
|
2023-10-25 10:18:57 +00:00
|
|
|
import { AppLayout } from "layouts/app-layout";
|
2023-11-01 08:15:04 +00:00
|
|
|
import { ProjectSettingLayout } from "layouts/settings-layout";
|
2023-07-13 06:04:37 +00:00
|
|
|
// hooks
|
|
|
|
import useToast from "hooks/use-toast";
|
|
|
|
// components
|
|
|
|
import { AutoArchiveAutomation, AutoCloseAutomation } from "components/automation";
|
2023-10-18 13:47:02 +00:00
|
|
|
import { ProjectSettingHeader } from "components/headers";
|
2023-07-13 06:04:37 +00:00
|
|
|
// types
|
2023-11-02 18:27:44 +00:00
|
|
|
import { NextPageWithLayout } from "types/app";
|
2023-07-13 06:04:37 +00:00
|
|
|
import { IProject } from "types";
|
|
|
|
|
2023-11-14 13:03:01 +00:00
|
|
|
const AutomationSettingsPage: NextPageWithLayout = observer(() => {
|
2023-07-13 06:04:37 +00:00
|
|
|
const router = useRouter();
|
|
|
|
const { workspaceSlug, projectId } = router.query;
|
|
|
|
|
|
|
|
const { setToastAlert } = useToast();
|
|
|
|
|
2023-11-14 13:03:01 +00:00
|
|
|
// store
|
|
|
|
const {
|
|
|
|
user: { currentProjectRole },
|
|
|
|
project: { currentProjectDetails: projectDetails, updateProject },
|
|
|
|
} = useMobxStore();
|
2023-10-04 13:54:13 +00:00
|
|
|
|
2023-07-13 06:04:37 +00:00
|
|
|
const handleChange = async (formData: Partial<IProject>) => {
|
2023-07-14 09:38:07 +00:00
|
|
|
if (!workspaceSlug || !projectId || !projectDetails) return;
|
2023-07-13 06:04:37 +00:00
|
|
|
|
2023-11-14 13:03:01 +00:00
|
|
|
await updateProject(workspaceSlug.toString(), projectId.toString(), formData).catch(() => {
|
|
|
|
setToastAlert({
|
|
|
|
type: "error",
|
|
|
|
title: "Error!",
|
|
|
|
message: "Something went wrong. Please try again.",
|
2023-07-13 06:04:37 +00:00
|
|
|
});
|
2023-11-14 13:03:01 +00:00
|
|
|
});
|
2023-07-13 06:04:37 +00:00
|
|
|
};
|
|
|
|
|
2023-11-14 13:03:01 +00:00
|
|
|
const isAdmin = currentProjectRole === 20;
|
2023-10-04 13:54:13 +00:00
|
|
|
|
2023-11-02 18:27:44 +00:00
|
|
|
return (
|
|
|
|
<section className={`pr-9 py-8 w-full overflow-y-auto ${isAdmin ? "" : "opacity-60"}`}>
|
2023-11-07 07:42:05 +00:00
|
|
|
<div className="flex items-center py-3.5 border-b border-custom-border-100">
|
2023-11-02 18:27:44 +00:00
|
|
|
<h3 className="text-xl font-medium">Automations</h3>
|
|
|
|
</div>
|
2023-11-08 12:04:42 +00:00
|
|
|
<AutoArchiveAutomation handleChange={handleChange} />
|
|
|
|
<AutoCloseAutomation handleChange={handleChange} />
|
2023-11-02 18:27:44 +00:00
|
|
|
</section>
|
|
|
|
);
|
2023-11-14 13:03:01 +00:00
|
|
|
});
|
2023-11-02 18:27:44 +00:00
|
|
|
|
|
|
|
AutomationSettingsPage.getLayout = function getLayout(page: ReactElement) {
|
2023-07-13 06:04:37 +00:00
|
|
|
return (
|
2023-10-25 10:18:57 +00:00
|
|
|
<AppLayout header={<ProjectSettingHeader title="Automations Settings" />} withProjectWrapper>
|
2023-11-02 18:27:44 +00:00
|
|
|
<ProjectSettingLayout>{page}</ProjectSettingLayout>
|
2023-10-25 10:18:57 +00:00
|
|
|
</AppLayout>
|
2023-07-13 06:04:37 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2023-11-02 18:27:44 +00:00
|
|
|
export default AutomationSettingsPage;
|