Skip to content

Commit

Permalink
add cart backwards compatibility + default images (#628)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexzhang1618 authored Jan 1, 2024
1 parent 9da4d37 commit bc0c010
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/store/components/OrderDisplay/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,11 @@ const OrderDisplay: React.FC<OrderDisplayProps> = (props) => {
const updatedItems = Array.from(itemMap, ([, value]) => value);

const orderData = updatedItems.map((orderItem) => {
const picture = orderItem.option.item.uploadedPhoto;
const {
uuid,
option: {
item: { itemName, picture },
item: { itemName },
metadata,
},
quantity,
Expand Down
5 changes: 4 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ export interface PublicMerchItem {
uuid: Uuid;
itemName: string;
collection?: PublicMerchCollection;
// Old remnant of when merch photos were only restricted to one.
// This is kept here so older carts are still backwards compatible.
picture?: string;
merchPhotos: {
uuid: string;
uploadedPhoto: string;
Expand Down Expand Up @@ -106,7 +109,7 @@ export interface CartItem {
export interface PublicCartMerchItem {
uuid: Uuid;
itemName: string;
picture: string;
uploadedPhoto: string;
description: string;
}

Expand Down
8 changes: 6 additions & 2 deletions src/utils.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { notification } from 'antd';
import NoImage from './assets/graphics/cat404.png';

import Storage from './storage';
import { HttpRequestMethod, MimeType, FetchServiceOptions, PublicMerchItemOption, OrderStatus, PublicMerchItem } from './types';
Expand Down Expand Up @@ -314,10 +315,13 @@ export const parseOrderStatus = (status: OrderStatus) => {
* Given a merch item, return the first picture associated with it.
*/
export const getDefaultMerchItemPicture = (item: PublicMerchItem | undefined): string | undefined => {
if (item && item.merchPhotos.length !== 0) {
if (item?.picture) {
return item.picture;
}
if (item?.merchPhotos?.length) {
// Get the item here with the smallest position (since it doesn't always arrive sorted)
item.merchPhotos.sort((a, b) => a.position - b.position);
return item.merchPhotos[0].uploadedPhoto;
}
return undefined;
return NoImage;
};

0 comments on commit bc0c010

Please sign in to comment.