From c4348d6d3d1f216a21a7c71643938e5e656486fd Mon Sep 17 00:00:00 2001 From: Angel Beltran Date: Wed, 21 Jan 2026 00:40:33 -0700 Subject: [PATCH] updated draft sync group table buttons upon table change --- go.mod | 4 +-- go.sum | 4 --- internal/domains/accounts/dev.go | 36 +++++++++---------- .../draft/table/add-listing-button.html.tmpl | 15 ++++++++ .../index.html.tmpl} | 20 ++++++++++- .../table/save-sync-group-button.html.tmpl | 33 +++++++++++++++++ templates/components/button.html.tmpl | 6 +++- .../{acctID.int64}/inventory.html.tmpl | 34 ++---------------- 8 files changed, 95 insertions(+), 57 deletions(-) create mode 100644 templates/components/accounts/{acctID.int64}/inventory/sync-groups/draft/table/add-listing-button.html.tmpl rename templates/components/accounts/{acctID.int64}/inventory/sync-groups/draft/{table.html.tmpl => table/index.html.tmpl} (72%) create mode 100644 templates/components/accounts/{acctID.int64}/inventory/sync-groups/draft/table/save-sync-group-button.html.tmpl diff --git a/go.mod b/go.mod index 51e62d7..6f1abd0 100644 --- a/go.mod +++ b/go.mod @@ -2,12 +2,12 @@ module ruben/inventory2 go 1.24.2 -// replace github.com/angelbeltran/templater v0.2.2 => ../../github.com/angelbeltran/templater +replace github.com/angelbeltran/templater v0.2.3 => ../../github.com/angelbeltran/templater require github.com/jackc/pgx/v5 v5.7.6 require ( - github.com/angelbeltran/templater v0.2.2 + github.com/angelbeltran/templater v0.2.3 github.com/coreos/go-oidc/v3 v3.8.0 github.com/gin-gonic/gin v1.9.1 github.com/google/uuid v1.5.0 diff --git a/go.sum b/go.sum index ba8ca39..310ac28 100644 --- a/go.sum +++ b/go.sum @@ -9,10 +9,6 @@ github.com/alecthomas/units v0.0.0-20231202071711-9a357b53e9c9 h1:ez/4by2iGztzR4 github.com/alecthomas/units v0.0.0-20231202071711-9a357b53e9c9/go.mod h1:OMCwj8VM1Kc9e19TLln2VL61YJF0x1XFtfdL4JdbSyE= github.com/angelbeltran/concurry v0.0.0-20260109231127-8e2678d8928c h1:BIa061RHaIVP9TjpIQf0PldVpQmeln/2U1Cf2w8ALNI= github.com/angelbeltran/concurry v0.0.0-20260109231127-8e2678d8928c/go.mod h1:Aii6F8lZCJb8Ns0d1FH35bDxNoyiuvwXd5BYJroJnks= -github.com/angelbeltran/templater v0.2.1 h1:9N2eNRE5/sYUgu7nZrU6VSSrrpKcOTlAw+UeeK3kyhk= -github.com/angelbeltran/templater v0.2.1/go.mod h1:ZA0T/ZmXxPi3gFjgp+RwEkcY9Q+JGyMStGw0c1jvgqA= -github.com/angelbeltran/templater v0.2.2 h1:SwsX7RrHtpjDvSi87CYqBRJsZFGaIHmGjn/clfqYqq4= -github.com/angelbeltran/templater v0.2.2/go.mod h1:ZA0T/ZmXxPi3gFjgp+RwEkcY9Q+JGyMStGw0c1jvgqA= github.com/apapsch/go-jsonmerge/v2 v2.0.0 h1:axGnT1gRIfimI7gJifB699GoE/oq+F2MU7Dml6nw9rQ= github.com/apapsch/go-jsonmerge/v2 v2.0.0/go.mod h1:lvDnEdqiQrp0O42VQGgmlKpxL1AP2+08jFMw88y4klk= github.com/bmatcuk/doublestar v1.1.1/go.mod h1:UD6OnuiIn0yFxxA2le/rnRU1G4RaI4UvFv1sNto9p6w= diff --git a/internal/domains/accounts/dev.go b/internal/domains/accounts/dev.go index a77f155..3206c86 100644 --- a/internal/domains/accounts/dev.go +++ b/internal/domains/accounts/dev.go @@ -102,7 +102,7 @@ var ( AccountID: 6, }, Platform: Etsy, - ShopID: "1", + ShopID: "2", }, ListingID: "1", }, @@ -118,7 +118,7 @@ var ( AccountID: 6, }, Platform: Etsy, - ShopID: "1", + ShopID: "2", }, ListingID: "2", }, @@ -134,7 +134,7 @@ var ( AccountID: 6, }, Platform: Etsy, - ShopID: "1", + ShopID: "2", }, ListingID: "3", }, @@ -149,8 +149,8 @@ var ( AccountIDs: AccountIDs{ AccountID: 6, }, - Platform: Tiktok, - ShopID: "4", + Platform: Etsy, + ShopID: "2", }, ListingID: "4", }, @@ -165,8 +165,8 @@ var ( AccountIDs: AccountIDs{ AccountID: 6, }, - Platform: Tiktok, - ShopID: "4", + Platform: Etsy, + ShopID: "2", }, ListingID: "5", }, @@ -181,8 +181,8 @@ var ( AccountIDs: AccountIDs{ AccountID: 6, }, - Platform: Tiktok, - ShopID: "4", + Platform: Etsy, + ShopID: "2", }, ListingID: "6", }, @@ -197,8 +197,8 @@ var ( AccountIDs: AccountIDs{ AccountID: 6, }, - Platform: Wix, - ShopID: "7", + Platform: Etsy, + ShopID: "5", }, ListingID: "7", }, @@ -213,8 +213,8 @@ var ( AccountIDs: AccountIDs{ AccountID: 6, }, - Platform: Wix, - ShopID: "7", + Platform: Etsy, + ShopID: "5", }, ListingID: "8", }, @@ -229,8 +229,8 @@ var ( AccountIDs: AccountIDs{ AccountID: 6, }, - Platform: Wix, - ShopID: "7", + Platform: Etsy, + ShopID: "5", }, ListingID: "9", }, @@ -246,7 +246,7 @@ var ( AccountID: 6, }, Platform: Etsy, - ShopID: "2", + ShopID: "5", }, ListingID: "10", }, @@ -262,7 +262,7 @@ var ( AccountID: 6, }, Platform: Etsy, - ShopID: "2", + ShopID: "5", }, ListingID: "11", }, @@ -278,7 +278,7 @@ var ( AccountID: 6, }, Platform: Etsy, - ShopID: "2", + ShopID: "5", }, ListingID: "12", }, diff --git a/templates/components/accounts/{acctID.int64}/inventory/sync-groups/draft/table/add-listing-button.html.tmpl b/templates/components/accounts/{acctID.int64}/inventory/sync-groups/draft/table/add-listing-button.html.tmpl new file mode 100644 index 0000000..f9b43dc --- /dev/null +++ b/templates/components/accounts/{acctID.int64}/inventory/sync-groups/draft/table/add-listing-button.html.tmpl @@ -0,0 +1,15 @@ +{{- $acctID := .PathParams.acctID }} + + +{{- component "button" + "HXPost" (printf "/api/accounts/%d/inventory/sync-groups/draft/listings" $acctID) + "HXTarget" "#accounts-acct-id-inventory-sync-groups-draft-table" + "HXSwap" "outerHTML" + "ID" "sync-groups-draft-table-add-listing-button" + "Class" "mt-[1em] mb-[1em]" + "Text" "Add Listing" + "_" ` + on click + send rowUpdated to the first in #accounts-acct-id-inventory-sync-groups-draft-table + ` +}} diff --git a/templates/components/accounts/{acctID.int64}/inventory/sync-groups/draft/table.html.tmpl b/templates/components/accounts/{acctID.int64}/inventory/sync-groups/draft/table/index.html.tmpl similarity index 72% rename from templates/components/accounts/{acctID.int64}/inventory/sync-groups/draft/table.html.tmpl rename to templates/components/accounts/{acctID.int64}/inventory/sync-groups/draft/table/index.html.tmpl index ff272d6..f9c1524 100644 --- a/templates/components/accounts/{acctID.int64}/inventory/sync-groups/draft/table.html.tmpl +++ b/templates/components/accounts/{acctID.int64}/inventory/sync-groups/draft/table/index.html.tmpl @@ -2,7 +2,6 @@ {{- $acctID := .PathParams.acctID }} -{{- $stores := .Accounts.GetShops $acctID -}}
+{{/* + + */}} + + diff --git a/templates/components/accounts/{acctID.int64}/inventory/sync-groups/draft/table/save-sync-group-button.html.tmpl b/templates/components/accounts/{acctID.int64}/inventory/sync-groups/draft/table/save-sync-group-button.html.tmpl new file mode 100644 index 0000000..54a7d4c --- /dev/null +++ b/templates/components/accounts/{acctID.int64}/inventory/sync-groups/draft/table/save-sync-group-button.html.tmpl @@ -0,0 +1,33 @@ +{{/* TODO: save the listings as a sync group on click */}} + + +{{- $acctID := .PathParams.acctID }} +{{- $listings := .Accounts.GetSyncGroupListingDrafts $acctID }} + +{{- $numCompletedListings := 0 }} +{{- range $l := $listings }} + {{- if and $l.ShopID $l.ListingID }} + {{- $numCompletedListings = (addInt $numCompletedListings 1) }} + {{- else }} + {{- end }} +{{- end }} + +{{- $enoughListings := gt $numCompletedListings 1 }} +{{- $allCompleted := len $listings | eq $numCompletedListings }} + + +{{ component "button" + "ID" "create-sync-group-button" + "HXPost" (printf "/api/accounts/%d/sync-groups" $acctID) + "Class" "mt-[1em] mb-[1em]" + "Text" "Save Sync Group" + "Disabled" (or (not $enoughListings) (not $allCompleted)) + "_" ` + on setDisabled(disabled) + if disabled then + add @disabled to me + else + remove @disabled from me + end + ` +}} diff --git a/templates/components/button.html.tmpl b/templates/components/button.html.tmpl index 4ef9742..3967cf4 100644 --- a/templates/components/button.html.tmpl +++ b/templates/components/button.html.tmpl @@ -1,4 +1,5 @@ -{{/* .HXGet | .HXPost | .HXDelete, .HXTarget, .HXSwap, .HXVals, ._, .Text, .ID, .Class, .Disabled */}} +{{/* .HXGet | .HXPost | .HXDelete, .HXTrigger, .HXTarget, .HXSwap, .HXVals, ._, .Text, .ID, .Class, .Disabled */}} +