Skip to content

Commit

Permalink
added create validations
Browse files Browse the repository at this point in the history
  • Loading branch information
shivankacker committed Aug 31, 2024
1 parent 31603bd commit 889e075
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Components/Facility/SpokeFacilityEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export default function SpokeFacilityEditor(props: SpokeFacilityEditorProps) {
disabled={processing}
filter={(f) =>
!!f.id &&
facility.id !== f.id &&
!spokes?.flatMap((s) => s.spoke_object.id).includes(f.id)
}
/>
Expand Down Expand Up @@ -144,6 +145,7 @@ export default function SpokeFacilityEditor(props: SpokeFacilityEditorProps) {
relationship: SpokeRelationship.REGULAR,
}}
createText="Add Spoke"
allowCreate={(item) => !item.relationship || !item.spoke}
>
{FormRender}
</ModelCrudEditor>
Expand Down
3 changes: 3 additions & 0 deletions src/Components/Form/ModelCrudEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface ModelCrudEditorProps<TRes extends Identifier, TReq, TErr> {
emptyText?: React.ReactNode;
empty: TReq;
createText?: React.ReactNode;
allowCreate?: (item: TReq) => boolean;
}

export default function ModelCrudEditor<TRes extends Identifier, TReq, TErr>(
Expand All @@ -39,6 +40,7 @@ export default function ModelCrudEditor<TRes extends Identifier, TReq, TErr>(
emptyText,
empty,
createText,
allowCreate,
} = props;
const [creating, setCreating] = useState(false);
const [updating, setUpdating] = useState<string | null>(null);
Expand Down Expand Up @@ -100,6 +102,7 @@ export default function ModelCrudEditor<TRes extends Identifier, TReq, TErr>(
type="button"
className="w-full py-3 md:w-auto"
loading={creating}
disabled={allowCreate?.(item as TReq)}
onClick={() => handleCreate(item as TReq)}
>
{createText || "Create"}
Expand Down

0 comments on commit 889e075

Please sign in to comment.