feat: add status page basic info change
This commit is contained in:
parent
b324536726
commit
c68d27a6d3
@ -5,21 +5,28 @@ import { z } from 'zod';
|
||||
|
||||
const { Text } = Typography;
|
||||
|
||||
interface Values {
|
||||
export interface MonitorStatusPageEditFormValues {
|
||||
title: string;
|
||||
slug: string;
|
||||
}
|
||||
|
||||
interface MonitorStatusPageEditFormProps {
|
||||
isLoading?: boolean;
|
||||
onFinish: (values: Values) => void;
|
||||
initialValues?: Partial<MonitorStatusPageEditFormValues>;
|
||||
onFinish: (values: MonitorStatusPageEditFormValues) => void;
|
||||
onCancel?: () => void;
|
||||
saveButtonLabel?: string;
|
||||
}
|
||||
|
||||
export const MonitorStatusPageEditForm: React.FC<MonitorStatusPageEditFormProps> =
|
||||
React.memo((props) => {
|
||||
return (
|
||||
<div>
|
||||
<Form<Values> layout="vertical" onFinish={props.onFinish}>
|
||||
<Form<MonitorStatusPageEditFormValues>
|
||||
layout="vertical"
|
||||
initialValues={props.initialValues}
|
||||
onFinish={props.onFinish}
|
||||
>
|
||||
<Form.Item
|
||||
label="Title"
|
||||
name="title"
|
||||
@ -64,9 +71,18 @@ export const MonitorStatusPageEditForm: React.FC<MonitorStatusPageEditFormProps>
|
||||
>
|
||||
<Input addonBefore={`${window.origin}/status/`} />
|
||||
</Form.Item>
|
||||
|
||||
<div className="flex gap-4">
|
||||
<Button type="primary" htmlType="submit" loading={props.isLoading}>
|
||||
Next
|
||||
{props.saveButtonLabel ?? 'Save'}
|
||||
</Button>
|
||||
|
||||
{props.onCancel && (
|
||||
<Button htmlType="button" onClick={props.onCancel}>
|
||||
Cancel
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</Form>
|
||||
</div>
|
||||
);
|
||||
|
@ -1,8 +1,15 @@
|
||||
import { Button, Empty } from 'antd';
|
||||
import React from 'react';
|
||||
import React, { useState } from 'react';
|
||||
import { trpc } from '../../../api/trpc';
|
||||
import { MonitorHealthBar } from '../MonitorHealthBar';
|
||||
import { useAllowEdit } from './useAllowEdit';
|
||||
import {
|
||||
MonitorStatusPageEditForm,
|
||||
MonitorStatusPageEditFormValues,
|
||||
} from './EditForm';
|
||||
import clsx from 'clsx';
|
||||
import { useRequest } from '../../../hooks/useRequest';
|
||||
import { useNavigate } from 'react-router';
|
||||
|
||||
interface MonitorStatusPageProps {
|
||||
slug: string;
|
||||
@ -15,16 +22,68 @@ export const MonitorStatusPage: React.FC<MonitorStatusPageProps> = React.memo(
|
||||
const { data: info } = trpc.monitor.getPageInfo.useQuery({
|
||||
slug,
|
||||
});
|
||||
const editPageMutation = trpc.monitor.editPage.useMutation();
|
||||
const trpcUtils = trpc.useContext();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const allowEdit = useAllowEdit(info?.workspaceId);
|
||||
const [editMode, setEditMode] = useState(false);
|
||||
|
||||
const monitorList = info?.monitorList ?? [];
|
||||
|
||||
const [{ loading }, handleSave] = useRequest(
|
||||
async (values: MonitorStatusPageEditFormValues) => {
|
||||
if (!info) {
|
||||
return;
|
||||
}
|
||||
|
||||
const newPageInfo = await editPageMutation.mutateAsync({
|
||||
id: info.id,
|
||||
workspaceId: info.workspaceId,
|
||||
...values,
|
||||
});
|
||||
|
||||
trpcUtils.monitor.getPageInfo.setData(
|
||||
{
|
||||
slug,
|
||||
},
|
||||
newPageInfo
|
||||
);
|
||||
setEditMode(false);
|
||||
|
||||
if (info.slug !== newPageInfo.slug) {
|
||||
// if slug is changed, should to navigate to new url
|
||||
navigate(`/status/${newPageInfo.slug}`);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="w-4/5 mx-auto py-8 ">
|
||||
<div className="w-full h-full flex gap-6">
|
||||
{editMode && (
|
||||
<div className="w-1/3 overflow-auto py-8 px-4 border-r border-gray-600">
|
||||
<MonitorStatusPageEditForm
|
||||
isLoading={loading}
|
||||
initialValues={info ?? {}}
|
||||
onFinish={handleSave}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<div
|
||||
className={clsx(
|
||||
'mx-auto py-8 overflow-auto',
|
||||
!editMode ? 'w-4/5' : 'w-2/3'
|
||||
)}
|
||||
>
|
||||
<div className="text-2xl mb-4">{info?.title}</div>
|
||||
|
||||
<div>{allowEdit && <Button type="primary">Edit</Button>}</div>
|
||||
<div>
|
||||
{allowEdit && !editMode && (
|
||||
<Button type="primary" onClick={() => setEditMode(true)}>
|
||||
Edit
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="text-lg mb-2">Services</div>
|
||||
|
||||
@ -51,6 +110,7 @@ export const MonitorStatusPage: React.FC<MonitorStatusPageProps> = React.memo(
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
);
|
||||
|
@ -32,6 +32,7 @@ export const MonitorPageAdd: React.FC = React.memo(() => {
|
||||
return (
|
||||
<div className="px-8 py-4">
|
||||
<MonitorStatusPageEditForm
|
||||
saveButtonLabel="Next"
|
||||
isLoading={createPageMutation.isLoading}
|
||||
onFinish={handleFinish}
|
||||
/>
|
||||
|
@ -523,6 +523,9 @@ export const monitorRouter = router({
|
||||
const existSlugCount = await prisma.monitorStatusPage.count({
|
||||
where: {
|
||||
slug,
|
||||
id: {
|
||||
not: id,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user