XYLEX Group
DevelopmentResource FrameworkCreate Resource

Create Resource Button

CreateResourceButton

A convenience wrapper that fetches resource_routes for a resourceName and opens CreateResourceDialog. It hides itself if enable_new_resource_creation is false or the route cannot be found.

Import

import { CreateResourceButton } from "@/packages/resource-framework/components/create-resource-button";
```typescript

### Props
- `resourceName: string` – the resource to create (matched against `resource_routes.resource_name`, then fallback to `"table"`)
- `label?: string` – override button label (default: DB-provided `new_resource_button_text` or `New ${page_label || resourceName}`)
- `className?: string` – optional classes
- `cacheEnabled?: boolean` – toggles `Cache-Control: no-cache` when false

### Behavior
- On mount, fetches `resource_routes` for the given `resourceName`.
- Renders nothing if creation is disabled or route is missing.
- Clicking the button opens `CreateResourceDialog` using the DB-derived `table`, `required`, `optional`, and `columns`.
- On successful create, reloads the page by default (override by forking the component or using the dialog directly).

### Example

```tsx
<CreateResourceButton resourceName="customers" />
```typescript

With custom label and caching:

```tsx
<CreateResourceButton
  resourceName="customers"
  label="Add customer"
  cacheEnabled={false}
/>
```typescript