mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
1e152c666c
* chore: moved app & space from apps to root * chore: modified workspace configuration * chore: modified dockerfiles for space and web * chore: modified icons for space * feat: updated files for new svg icons supported by next-images * chore: added /spaces base path for next * chore: added compose config for space * chore: updated husky configuration * chore: updated workflows for new configuration * chore: changed app name to web * fix: resolved build errors with web * chore: reset file tracing root for both projects * chore: added nginx config for deploy * fix: eslint and tsconfig settings for space app * husky setup fixes based on new dir * eslint fixes * prettier formatting --------- Co-authored-by: Henit Chobisa <chobisa.henit@gmail.com>
90 lines
2.2 KiB
TypeScript
90 lines
2.2 KiB
TypeScript
import { useEffect } from "react";
|
|
|
|
// react-hook-form
|
|
import { useForm } from "react-hook-form";
|
|
// ui
|
|
import { Input, Loader, PrimaryButton, SecondaryButton } from "components/ui";
|
|
// types
|
|
import { IPage } from "types";
|
|
|
|
type Props = {
|
|
handleFormSubmit: (values: IPage) => Promise<void>;
|
|
handleClose: () => void;
|
|
status: boolean;
|
|
data?: IPage | null;
|
|
};
|
|
|
|
const defaultValues = {
|
|
name: "",
|
|
description: "",
|
|
};
|
|
|
|
export const PageForm: React.FC<Props> = ({ handleFormSubmit, handleClose, status, data }) => {
|
|
const {
|
|
register,
|
|
formState: { errors, isSubmitting },
|
|
handleSubmit,
|
|
reset,
|
|
} = useForm<IPage>({
|
|
defaultValues,
|
|
});
|
|
|
|
const handleCreateUpdatePage = async (formData: IPage) => {
|
|
await handleFormSubmit(formData);
|
|
|
|
reset({
|
|
...defaultValues,
|
|
});
|
|
};
|
|
|
|
useEffect(() => {
|
|
reset({
|
|
...defaultValues,
|
|
...data,
|
|
});
|
|
}, [data, reset]);
|
|
|
|
return (
|
|
<form onSubmit={handleSubmit(handleCreateUpdatePage)}>
|
|
<div className="space-y-5">
|
|
<h3 className="text-lg font-medium leading-6 text-custom-text-100">
|
|
{status ? "Update" : "Create"} Page
|
|
</h3>
|
|
<div className="space-y-3">
|
|
<div>
|
|
<Input
|
|
id="name"
|
|
name="name"
|
|
type="name"
|
|
placeholder="Title"
|
|
className="resize-none text-xl"
|
|
autoComplete="off"
|
|
error={errors.name}
|
|
register={register}
|
|
validations={{
|
|
required: "Title is required",
|
|
maxLength: {
|
|
value: 255,
|
|
message: "Title should be less than 255 characters",
|
|
},
|
|
}}
|
|
/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div className="mt-5 flex justify-end gap-2">
|
|
<SecondaryButton onClick={handleClose}>Cancel</SecondaryButton>
|
|
<PrimaryButton type="submit" loading={isSubmitting}>
|
|
{status
|
|
? isSubmitting
|
|
? "Updating Page..."
|
|
: "Update Page"
|
|
: isSubmitting
|
|
? "Creating Page..."
|
|
: "Create Page"}
|
|
</PrimaryButton>
|
|
</div>
|
|
</form>
|
|
);
|
|
};
|