feat: Adds purchase-order form only renders a new row rather than whole table.

This commit is contained in:
2025-01-09 22:34:49 -05:00
parent c4410706fd
commit 3f30327fd8
5 changed files with 35 additions and 16 deletions

View File

@@ -102,6 +102,8 @@ struct ApiController: RouteCollection {
// MARK: - PurchaseOrders
// TODO: Add fetch by id.
// TODO: Add pagination and filters.
@Sendable
func purchaseOrdersIndex(req: Request) async throws -> [PurchaseOrder.DTO] {

View File

@@ -42,9 +42,19 @@ struct PurchaseOrderViewController: RouteCollection {
let purchaseOrder = create.toModel(createdByID: createdById)
try await purchaseOrder.save(on: req.db)
let loaded = try await PurchaseOrder.query(on: req.db)
.filter(\.$id == purchaseOrder.requireID())
.with(\.$createdFor)
.with(\.$createdBy)
.with(\.$vendorBranch) {
$0.with(\.$vendor)
}
.first()
let purchaseOrders = try await api.purchaseOrdersIndex(req: req)
return try await req.view.render("purchaseOrders/table", ["purchaseOrders": purchaseOrders])
return try await req.view.render("purchaseOrders/table-row", loaded)
// let purchaseOrders = try await api.purchaseOrdersIndex(req: req)
// return try await req.view.render("purchaseOrders/table", ["purchaseOrders": purchaseOrders])
}
}
@@ -67,11 +77,11 @@ private struct PurchaseOrderFormCTX: Content {
formClass: "po-form",
formId: "po-form",
htmxTargetUrl: .post("/purchase-orders"),
htmxTarget: "#po-table",
htmxTarget: "#po-table-body",
htmxPushUrl: false,
htmxResetAfterRequest: true,
htmxSwapOob: nil,
htmxSwap: .outerHTML,
htmxSwap: .afterbegin,
context: .init(branches: branches, employees: employees)
))
}