Skip to content

Editing

These examples extend the Web orders List. Users need the relevant permissions to edit, create, or delete records.

To let Sales edit an order’s quantity, add a detail form, a query that loads the selected order, and an update callback. Keep id in the List’s output and query results so the Dashboard can open the right record.

Put the form schema in a separate file:

src/order-forms.ts
import { NumberField } from "@pf/form-schema"
import { Schema } from "effect"
export const editOrderForm = Schema.Struct({
quantity: NumberField({ label: "Quantity" }),
})

Keep the schema in a separate file because it is sent to the browser. The Dashboard uses it to display the form and check what the user enters. The server checks those values again before saving. Keep database code and credentials out of this file.

Import editOrderForm from that module and add these properties to the same new List configuration. This example updates the sample array in memory; in a deployed project, load and save the record in your database.

form: () => editOrderForm.fields,
browser: { entrypoint: "src/order-forms.ts", exportName: "editOrderForm" },
itemQuery: (id) => {
const order = orders.find((order) => order.id === id)
return Effect.succeed(order ? { quantity: order.quantity } : null)
},
update: (id, { quantity }) =>
Effect.sync(() => {
const order = orders.find((order) => order.id === id)
if (!order) return null
order.quantity = quantity
return { quantity: order.quantity }
}),

itemQuery supplies the current quantity to the form. On save, update receives the record ID and the submitted fields.

Use create to offer a Create record button, even when the List is empty. The creation form asks for both SKU and quantity, while the edit form only exposes quantity.

In src/order-forms.ts, add TextField to the @pf/form-schema import and export a second schema:

export const createOrderForm = Schema.Struct({
sku: TextField({ label: "SKU" }),
quantity: NumberField({ label: "Quantity" }),
})

Import createOrderForm and add this property to the List configuration:

create: {
form: () => createOrderForm.fields,
browser: { entrypoint: "src/order-forms.ts", exportName: "createOrderForm" },
submit: ({ sku, quantity }) =>
Effect.sync(() => {
const id = crypto.randomUUID()
orders.push({ id, sku, quantity })
return id
}),
},

The server generates and returns the new record’s ID. In a deployed project, insert the record into your database before returning its ID. Direct creation adds a record without starting a process or creating a To-Do. If new orders need approval or other follow-up work, start a process.

To let authorised users delete a web order, add a delete callback to the same List configuration. The server passes the selected record’s ID to the callback.

delete: (id) =>
Effect.sync(() => {
const index = orders.findIndex((order) => order.id === id)
if (index !== -1) {
orders.splice(index, 1)
}
}),

This example removes the order from the in-memory array. In a deployed project, delete the record from your database by ID.