update sync group draft table shop listing options based on selected shops

This commit is contained in:
2026-01-20 23:25:03 -07:00
parent 4f2ae26d58
commit de18de49e9
2 changed files with 35 additions and 13 deletions
@@ -1,3 +1,4 @@
{{/* optional props: .Listings = .Accounts.GetSyncGroupListingDrafts */}}
{{/* TODO: make the save button disabled based on an api call */}} {{/* TODO: make the save button disabled based on an api call */}}
{{- $acctID := .PathParams.acctID }} {{- $acctID := .PathParams.acctID }}
@@ -7,6 +8,11 @@
{{- $selectedShopID := $entry.ShopID }} {{- $selectedShopID := $entry.ShopID }}
{{- $selectedListingID := $entry.ListingID }} {{- $selectedListingID := $entry.ListingID }}
{{- $listings := .Listings }}
{{- if not $listings }}
{{- $listings = .Accounts.GetSyncGroupListingDrafts $acctID }}
{{- end }}
<tr _=" <tr _="
init init
@@ -26,6 +32,7 @@
" "
> >
<td> <td>
{{/* TODO: filter out shops that are already selected */}}
{{- $shops := .Accounts.GetShops $acctID -}} {{- $shops := .Accounts.GetShops $acctID -}}
<select <select
class="min-w-fit cursor-pointer" class="min-w-fit cursor-pointer"
@@ -43,6 +50,19 @@
> >
<option disabled {{- if not $selectedShopID }}selected{{- end }}>- Shops -</option> <option disabled {{- if not $selectedShopID }}selected{{- end }}>- Shops -</option>
{{- range $shop := $shops }} {{- range $shop := $shops }}
{{- $shopSelectedInOtherListing := false }}
{{- if not (eq $shop.ShopID $selectedShopID ) }}
{{- range $listing := $listings }}
{{- if eq $listing.ShopID $shop.ShopID }}
{{- $shopSelectedInOtherListing = true }}
{{- break }}
{{- end }}
{{- end }}
{{- if $shopSelectedInOtherListing }}
{{- continue }}
{{- end }}
{{- end }}
{{- $isSelectedShop := and {{- $isSelectedShop := and
(eq $selectedShopPlatform $shop.Platform) (eq $selectedShopPlatform $shop.Platform)
(eq $selectedShopID $shop.ShopID) (eq $selectedShopID $shop.ShopID)
@@ -60,8 +80,8 @@
<td> <td>
{{- $selectedListing := "" }} {{- $selectedListing := "" }}
{{- if $selectedShopID }} {{- if $selectedShopID }}
{{- $listings := .Accounts.GetListingsForShop $acctID $selectedShopPlatform $selectedShopID }} {{- $shopListings := .Accounts.GetListingsForShop $acctID $selectedShopPlatform $selectedShopID }}
{{- if $listings }} {{- if $shopListings }}
<select <select
class="min-w-fit cursor-pointer" class="min-w-fit cursor-pointer"
@@ -79,19 +99,19 @@
" "
> >
<option disabled {{if not $selectedListingID}}selected{{end}}>- Listings -</option> <option disabled {{if not $selectedListingID}}selected{{end}}>- Listings -</option>
{{- range $i, $listing := $listings }} {{- range $i, $shopListing := $shopListings }}
{{- if eq $selectedListingID $listing.ListingID }} {{- if eq $selectedListingID $shopListing.ListingID }}
{{ $selectedListing = $listing }} {{ $selectedListing = $shopListing }}
{{- end }} {{- end }}
<option <option
value="{{$listing.ListingID}}" value="{{$shopListing.ListingID}}"
{{if eq $selectedListingID $listing.ListingID}}selected{{end}} {{if eq $selectedListingID $shopListing.ListingID}}selected{{end}}
data-name="{{ $listing.Name }}" data-name="{{ $shopListing.Name }}"
data-sku="{{ $listing.SKU }}" data-sku="{{ $shopListing.SKU }}"
data-description="{{ $listing.Description }}" data-description="{{ $shopListing.Description }}"
data-count="{{ $listing.Count }}" data-count="{{ $shopListing.Count }}"
> >
{{ $listing.Name }} {{ $shopListing.Name }}
</option> </option>
{{- end }} {{- end }}
</select> </select>
@@ -56,7 +56,9 @@
> >
{{- $listings := .Accounts.GetSyncGroupListingDrafts $acctID }} {{- $listings := .Accounts.GetSyncGroupListingDrafts $acctID }}
{{- range $listing := $listings }} {{- range $listing := $listings }}
{{- component (printf "accounts/%d/inventory/sync-groups/draft/listings/%d" $acctID $listing.OrderIndex) }} {{- component (printf "accounts/%d/inventory/sync-groups/draft/listings/%d" $acctID $listing.OrderIndex)
"Listings" $listings
}}
{{- end }} {{- end }}
</tbody> </tbody>
<tfoot> <tfoot>