mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 20:37:21 +00:00
fix system entity registration by re-applying configs to modules
This commit is contained in:
@@ -8,7 +8,6 @@ import {
|
||||
} from "@tabler/icons-react";
|
||||
import { ucFirst } from "core/utils";
|
||||
import { useEffect, useState } from "react";
|
||||
import { TbCirclesRelation, TbSettings } from "react-icons/tb";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
import { useBknd } from "ui/client/bknd";
|
||||
import { useBkndData } from "ui/client/schema/data/use-bknd-data";
|
||||
@@ -76,6 +75,10 @@ export function StepCreate() {
|
||||
try {
|
||||
const res = await item.run();
|
||||
setStates((prev) => [...prev, res]);
|
||||
if (res !== true) {
|
||||
// make sure to break out
|
||||
break;
|
||||
}
|
||||
} catch (e) {
|
||||
setStates((prev) => [...prev, (e as any).message]);
|
||||
}
|
||||
@@ -147,12 +150,14 @@ const SummaryItem: React.FC<SummaryItemProps> = ({
|
||||
}) => {
|
||||
const [expanded, handlers] = useDisclosure(initialExpanded);
|
||||
const error = typeof state !== "undefined" && state !== true;
|
||||
const done = state === true;
|
||||
|
||||
return (
|
||||
<div
|
||||
className={twMerge(
|
||||
"flex flex-col border border-muted rounded bg-background mb-2",
|
||||
error && "bg-red-500/20"
|
||||
error && "bg-red-500/20",
|
||||
done && "bg-green-500/20"
|
||||
)}
|
||||
>
|
||||
<div className="flex flex-row gap-4 px-2 py-2 items-center">
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
transformObject
|
||||
} from "core/utils";
|
||||
import type { MediaFieldConfig } from "media/MediaField";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useForm } from "react-hook-form";
|
||||
import { useBknd } from "ui/client/bknd";
|
||||
import { MantineNumberInput } from "ui/components/form/hook-form-mantine/MantineNumberInput";
|
||||
@@ -35,14 +36,15 @@ export function TemplateMediaComponent() {
|
||||
const {
|
||||
register,
|
||||
handleSubmit,
|
||||
formState: { isValid },
|
||||
setValue,
|
||||
formState: { isValid, errors },
|
||||
watch,
|
||||
control
|
||||
} = useForm({
|
||||
mode: "onChange",
|
||||
resolver: typeboxResolver(schema),
|
||||
defaultValues: Default(schema, state.initial ?? {}) as TCreateModalMediaSchema
|
||||
});
|
||||
const [forbidden, setForbidden] = useState<boolean>(false);
|
||||
|
||||
const { config } = useBknd();
|
||||
const media_enabled = config.media.enabled ?? false;
|
||||
@@ -51,13 +53,16 @@ export function TemplateMediaComponent() {
|
||||
name !== media_entity ? entity : undefined
|
||||
);
|
||||
const data = watch();
|
||||
const forbidden_field_names = Object.keys(config.data.entities?.[data.entity]?.fields ?? {});
|
||||
|
||||
useEffect(() => {
|
||||
setForbidden(forbidden_field_names.includes(data.name));
|
||||
}, [forbidden_field_names, data.name]);
|
||||
|
||||
async function handleCreate() {
|
||||
if (isValid) {
|
||||
console.log("data", data);
|
||||
if (isValid && !forbidden) {
|
||||
const { field, relation } = convert(media_entity, data);
|
||||
|
||||
console.log("state", { field, relation });
|
||||
setState((prev) => ({
|
||||
...prev,
|
||||
fields: { create: [field] },
|
||||
@@ -120,6 +125,13 @@ export function TemplateMediaComponent() {
|
||||
data.entity ? data.entity : "the entity"
|
||||
}.`}
|
||||
{...register("name")}
|
||||
error={
|
||||
errors.name?.message
|
||||
? errors.name?.message
|
||||
: forbidden
|
||||
? `Property "${data.name}" already exists on entity ${data.entity}`
|
||||
: undefined
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
{/*<p>step template media</p>
|
||||
@@ -129,7 +141,7 @@ export function TemplateMediaComponent() {
|
||||
<ModalFooter
|
||||
next={{
|
||||
type: "submit",
|
||||
disabled: !isValid || !media_enabled
|
||||
disabled: !isValid || !media_enabled || forbidden
|
||||
}}
|
||||
prev={{
|
||||
onClick: stepBack
|
||||
|
||||
Reference in New Issue
Block a user