From 90e61d1cbb812cb55ff8eb6812e366d93b2266af Mon Sep 17 00:00:00 2001 From: Dave Walker Date: Tue, 28 Nov 2023 18:33:25 +0000 Subject: [PATCH] Fixup purchase details retailer selection bug --- docker/ui/Dockerfile | 4 +- .../components/albumPurchaseDetails.js | 27 +++----- .../components/genreSelector.js | 4 +- .../components/retailerSelector.js | 62 +++++++++++++++++++ src/music-catalogue-ui/helpers/apiAlbums.js | 16 ++--- src/music-catalogue-ui/hooks/useRetailers.js | 2 +- 6 files changed, 78 insertions(+), 37 deletions(-) create mode 100644 src/music-catalogue-ui/components/retailerSelector.js diff --git a/docker/ui/Dockerfile b/docker/ui/Dockerfile index 354d8fb..cef9cc2 100644 --- a/docker/ui/Dockerfile +++ b/docker/ui/Dockerfile @@ -1,6 +1,6 @@ FROM node:20-alpine -COPY musiccatalogue.ui-1.25.0.0 /opt/musiccatalogue.ui-1.25.0.0 -WORKDIR /opt/musiccatalogue.ui-1.25.0.0 +COPY musiccatalogue.ui-1.26.0.0 /opt/musiccatalogue.ui-1.26.0.0 +WORKDIR /opt/musiccatalogue.ui-1.26.0.0 RUN npm install RUN npm run build ENTRYPOINT [ "npm", "start" ] diff --git a/src/music-catalogue-ui/components/albumPurchaseDetails.js b/src/music-catalogue-ui/components/albumPurchaseDetails.js index 9dbc702..df2d4f2 100644 --- a/src/music-catalogue-ui/components/albumPurchaseDetails.js +++ b/src/music-catalogue-ui/components/albumPurchaseDetails.js @@ -5,8 +5,7 @@ import CurrencyInput from "react-currency-input-field"; import config from "../config.json"; import pages from "@/helpers/navigation"; import { apiSetAlbumPurchaseDetails } from "@/helpers/apiAlbums"; -import Select from "react-select"; -import useRetailers from "@/hooks/useRetailers"; +import RetailerSelector from "./retailerSelector"; /** * Form to set the album purchase details for an album @@ -17,22 +16,12 @@ import useRetailers from "@/hooks/useRetailers"; * @param {*} logout */ const AlbumPurchaseDetails = ({ artist, album, navigate, logout }) => { - const { retailers: retailers, setRetailers } = useRetailers(logout); - - // Construct the options for the retailer drop-down - let options = []; - for (let i = 0; i < retailers.length; i++) { - options = [ - ...options, - { value: retailers[i].id, label: retailers[i].name }, - ]; - } - // Get the initial retailer selection and purchase date let initialRetailer = null; let initialPurchaseDate = new Date(); if (album != null) { - initialRetailer = options.find((x) => x.value == album.retailerId); + initialRetailer = album.retailer; + if (album.purchased != null) { initialPurchaseDate = new Date(album.purchased); } @@ -54,7 +43,7 @@ const AlbumPurchaseDetails = ({ artist, album, navigate, logout }) => { const updatedPurchaseDate = album.isWishListItem == false ? purchaseDate : null; const updatedPrice = price != undefined ? price : null; - const updatedRetailerId = retailer != null ? retailer.value.id : null; + const updatedRetailerId = retailer != null ? retailer.id : null; // Apply the updates const updatedAlbum = await apiSetAlbumPurchaseDetails( @@ -129,10 +118,10 @@ const AlbumPurchaseDetails = ({ artist, album, navigate, logout }) => { Retailer
- + ); +}; + +export default RetailerSelector; diff --git a/src/music-catalogue-ui/helpers/apiAlbums.js b/src/music-catalogue-ui/helpers/apiAlbums.js index 649b2e4..24219c6 100644 --- a/src/music-catalogue-ui/helpers/apiAlbums.js +++ b/src/music-catalogue-ui/helpers/apiAlbums.js @@ -215,9 +215,6 @@ const apiLookupAlbum = async ( * @returns */ const apiSetAlbumWishListFlag = async (album, wishListFlag, logout) => { - // Update the album properties - album.isWishListItem = wishListFlag; - // Send the update request to the API and return the response const response = await apiUpdateAlbum( album.id, @@ -226,7 +223,7 @@ const apiSetAlbumWishListFlag = async (album, wishListFlag, logout) => { album.title, album.released, album.coverUrl, - album.isWishListItem, + wishListFlag, album.purchased, album.price, album.retailerId, @@ -251,11 +248,6 @@ const apiSetAlbumPurchaseDetails = async ( retailerId, logout ) => { - // Update the purchase details - album.purchased = purchaseDate; - album.price = price; - album.retailerId = retailerId; - // Send the update request to the API and return the response const response = await apiUpdateAlbum( album.id, @@ -265,9 +257,9 @@ const apiSetAlbumPurchaseDetails = async ( album.released, album.coverUrl, album.isWishListItem, - album.purchased, - album.price, - album.retailerId, + purchaseDate, + price, + retailerId, logout ); return response; diff --git a/src/music-catalogue-ui/hooks/useRetailers.js b/src/music-catalogue-ui/hooks/useRetailers.js index eba50b4..e239d9b 100644 --- a/src/music-catalogue-ui/hooks/useRetailers.js +++ b/src/music-catalogue-ui/hooks/useRetailers.js @@ -24,7 +24,7 @@ const useRetailers = (logout) => { fetchReetailers(); }, [logout]); - return { retailers: retailers, setRetailers: setRetailers }; + return { retailers, setRetailers }; }; export default useRetailers;