Skip to content

Commit

Permalink
Merge pull request #1283 from hackclub/order-form-url-changes
Browse files Browse the repository at this point in the history
Changes to order form URL
  • Loading branch information
YodaLightsabr authored Jul 19, 2024
2 parents 11a8189 + 816f2be commit c48f180
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
9 changes: 5 additions & 4 deletions components/arcade/shop-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default function ShopComponent({
availableItems,
userAirtableID = null,
hoursBalance = null,
userEmail = null,
pub
}) {
// State to manage quantity for each item
Expand All @@ -38,9 +39,9 @@ export default function ShopComponent({
setQuantities({ ...quantities, [itemID]: quantity });
};

function buyLink(itemID) {
function buyLink(itemID, itemImage) {
const quantity = quantities[itemID] || 1; // Default quantity is 1 if not set
return `https://forms.hackclub.com/arcade-order?user_id=${userAirtableID}&item_id=${itemID}&quantity=${quantity}`;
return `https://forms.hackclub.com/arcade-order?user_id=${userAirtableID}&item_id=${itemID}&quantity=${quantity}&image=${encodeURIComponent(itemImage)}&email=${encodeURIComponent(userEmail)}`;
}

const canPurchaseItems = userAirtableID !== null;
Expand Down Expand Up @@ -87,7 +88,7 @@ export default function ShopComponent({
quantity={item['Max Order Quantity']}
fulfillmentDescription={item['Fulfillment Description']}
fullName={item['Full Name']}
link={canPurchaseItems ? buyLink(item.id) : null}
link={canPurchaseItems ? buyLink(item.id, item['Image URL']) : null}
key={item.id}
id={item.id}
onQuantityChange={(id, q) => handleQuantityChange(item.id, q)} // Pass handler to update quantity
Expand All @@ -111,7 +112,7 @@ export default function ShopComponent({
quantity={item['Max Order Quantity']}
fulfillmentDescription={item['Fulfillment Description']}
fullName={item['Full Name']}
link={canPurchaseItems ? buyLink(item.id) : null}
link={canPurchaseItems ? buyLink(item.id, item['Image URL']) : null}
key={item.id}
id={item.id}
onQuantityChange={(id, q) => handleQuantityChange(item.id, q)} // Pass handler to update quantity
Expand Down
7 changes: 7 additions & 0 deletions pages/arcade/[userAirtableID]/shop.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ body {
export default function Shop({
availableItems,
userAirtableID = null,
userEmail = null,
hoursBalance = 0
}) {
const [items, setItems] = useState(availableItems)
Expand Down Expand Up @@ -247,6 +248,7 @@ export default function Shop({
<ShopComponent
availableItems={aItems}
userAirtableID={userAirtableID}
userEmail={userEmail}
hoursBalance={hoursBalance}
/>
<Text
Expand All @@ -263,6 +265,7 @@ export default function Shop({
<ShopComponent
availableItems={bItems}
userAirtableID={userAirtableID}
userEmail={userEmail}
hoursBalance={hoursBalance}
/>
<Text
Expand All @@ -279,6 +282,7 @@ export default function Shop({
<ShopComponent
availableItems={cItems}
userAirtableID={userAirtableID}
userEmail={userEmail}
hoursBalance={hoursBalance}
/>
<Text
Expand All @@ -295,13 +299,15 @@ export default function Shop({
<ShopComponent
availableItems={dItems}
userAirtableID={userAirtableID}
userEmail={userEmail}
hoursBalance={hoursBalance}
/>
</>
) : (
<ShopComponent
availableItems={items}
userAirtableID={userAirtableID}
userEmail={userEmail}
hoursBalance={hoursBalance}
/>
)}
Expand Down Expand Up @@ -391,6 +397,7 @@ export async function getStaticProps({ params }) {
getArcadeUser(userAirtableID).then(user => {
const hoursBalance = user.fields['Balance (Hours)'] || 0
props.hoursBalance = hoursBalance
propts.userEmail = user.fields['Email']
})
])

Expand Down

0 comments on commit c48f180

Please sign in to comment.