2023-11-18 10:47:01 +00:00
|
|
|
import { FC } from "react";
|
|
|
|
import { Controller, useForm } from "react-hook-form";
|
|
|
|
// ui
|
|
|
|
import { Button, Input, ToggleSwitch } from "@plane/ui";
|
|
|
|
// types
|
2023-11-27 11:45:11 +00:00
|
|
|
import { IInstance, IInstanceAdmin } from "types/instance";
|
2023-11-18 10:47:01 +00:00
|
|
|
// hooks
|
|
|
|
import useToast from "hooks/use-toast";
|
|
|
|
import { useMobxStore } from "lib/mobx/store-provider";
|
|
|
|
|
|
|
|
export interface IInstanceGeneralForm {
|
|
|
|
instance: IInstance;
|
2023-11-27 11:45:11 +00:00
|
|
|
instanceAdmins: IInstanceAdmin[];
|
2023-11-18 10:47:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface GeneralFormValues {
|
|
|
|
instance_name: string;
|
2023-11-27 14:11:47 +00:00
|
|
|
// is_telemetry_enabled: boolean;
|
2023-11-18 10:47:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export const InstanceGeneralForm: FC<IInstanceGeneralForm> = (props) => {
|
2023-11-27 11:45:11 +00:00
|
|
|
const { instance, instanceAdmins } = props;
|
2023-11-18 10:47:01 +00:00
|
|
|
// store
|
|
|
|
const { instance: instanceStore } = useMobxStore();
|
|
|
|
// toast
|
|
|
|
const { setToastAlert } = useToast();
|
|
|
|
// form data
|
|
|
|
const {
|
|
|
|
handleSubmit,
|
|
|
|
control,
|
|
|
|
formState: { errors, isSubmitting },
|
|
|
|
} = useForm<GeneralFormValues>({
|
|
|
|
defaultValues: {
|
|
|
|
instance_name: instance.instance_name,
|
2023-11-27 14:11:47 +00:00
|
|
|
// is_telemetry_enabled: instance.is_telemetry_enabled,
|
2023-11-18 10:47:01 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const onSubmit = async (formData: GeneralFormValues) => {
|
|
|
|
const payload: Partial<GeneralFormValues> = { ...formData };
|
|
|
|
|
|
|
|
await instanceStore
|
|
|
|
.updateInstanceInfo(payload)
|
|
|
|
.then(() =>
|
|
|
|
setToastAlert({
|
|
|
|
title: "Success",
|
|
|
|
type: "success",
|
|
|
|
message: "Settings updated successfully",
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.catch((err) => console.error(err));
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2023-11-25 15:53:50 +00:00
|
|
|
<>
|
2023-11-27 11:45:11 +00:00
|
|
|
<div className="grid grid-col grid-cols-1 md:grid-cols-2 lg:grid-cols-3 items-center justify-between gap-8 w-full">
|
2023-11-18 10:47:01 +00:00
|
|
|
<div className="flex flex-col gap-1">
|
|
|
|
<h4 className="text-sm">Name of instance</h4>
|
|
|
|
<Controller
|
|
|
|
control={control}
|
|
|
|
name="instance_name"
|
|
|
|
render={({ field: { value, onChange, ref } }) => (
|
|
|
|
<Input
|
|
|
|
id="instance_name"
|
|
|
|
name="instance_name"
|
|
|
|
type="text"
|
|
|
|
value={value}
|
|
|
|
onChange={onChange}
|
|
|
|
ref={ref}
|
|
|
|
hasError={Boolean(errors.instance_name)}
|
|
|
|
placeholder="Instance Name"
|
|
|
|
className="rounded-md font-medium w-full"
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="flex flex-col gap-1">
|
2023-11-27 11:45:11 +00:00
|
|
|
<h4 className="text-sm">Admin email</h4>
|
2023-11-18 10:47:01 +00:00
|
|
|
<Input
|
2023-11-27 11:45:11 +00:00
|
|
|
id="email"
|
|
|
|
name="email"
|
2023-11-18 10:47:01 +00:00
|
|
|
type="email"
|
2023-11-27 11:45:11 +00:00
|
|
|
value={instanceAdmins[0].user_detail.email ?? ""}
|
|
|
|
placeholder="Admin email"
|
2023-11-18 10:47:01 +00:00
|
|
|
className="w-full cursor-not-allowed !text-custom-text-400"
|
|
|
|
disabled
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="flex flex-col gap-1">
|
2023-11-27 11:45:11 +00:00
|
|
|
<h4 className="text-sm">Instance ID</h4>
|
2023-11-18 10:47:01 +00:00
|
|
|
<Input
|
|
|
|
id="instance_id"
|
|
|
|
name="instance_id"
|
|
|
|
type="text"
|
|
|
|
value={instance.instance_id}
|
|
|
|
className="rounded-md font-medium w-full cursor-not-allowed !text-custom-text-400"
|
|
|
|
disabled
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2023-11-27 14:11:47 +00:00
|
|
|
{/* <div className="flex items-center gap-12 pt-4">
|
2023-11-18 10:47:01 +00:00
|
|
|
<div>
|
|
|
|
<div className="text-custom-text-100 font-medium text-sm">Share anonymous usage instance</div>
|
|
|
|
<div className="text-custom-text-300 font-normal text-xs">
|
|
|
|
Help us understand how you use Plane so we can build better for you.
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<Controller
|
|
|
|
control={control}
|
|
|
|
name="is_telemetry_enabled"
|
|
|
|
render={({ field: { value, onChange } }) => <ToggleSwitch value={value} onChange={onChange} size="sm" />}
|
|
|
|
/>
|
|
|
|
</div>
|
2023-11-27 14:11:47 +00:00
|
|
|
</div> */}
|
2023-11-18 10:47:01 +00:00
|
|
|
|
|
|
|
<div className="flex items-center py-1">
|
2023-11-27 14:11:47 +00:00
|
|
|
<Button variant="primary" onClick={handleSubmit(onSubmit)} loading={isSubmitting}>
|
|
|
|
{isSubmitting ? "Saving..." : "Save changes"}
|
2023-11-18 10:47:01 +00:00
|
|
|
</Button>
|
|
|
|
</div>
|
2023-11-25 15:53:50 +00:00
|
|
|
</>
|
2023-11-18 10:47:01 +00:00
|
|
|
);
|
|
|
|
};
|