Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added shop details #1044

Merged
merged 9 commits into from
Jan 12, 2025
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions lib/redis-lock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ async function aquireLock(key: string): Promise<string | null> {
return acquired ? lockValue : null
}

async function releaseLock(
lockKey: string,
lockValue: string,
): Promise<void> {
async function releaseLock(lockKey: string, lockValue: string): Promise<void> {
const currentLockValue = await kv.get(lockKey)
if (currentLockValue === lockValue) {
await kv.del(lockKey)
Expand Down
2 changes: 1 addition & 1 deletion src/app/harbor/shipyard/ships.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export default function Ships({
</Button>

<Modal isOpen={shipModal} close={() => setShipModal(false)}>
<div className="p-4 max-h-96 overflow-y-auto">
<div className="p-4 max-h-[70vh] overflow-y-auto">
<h2 className="text-3xl font-bold text-center">
Confirm Shipping
</h2>
Expand Down
90 changes: 86 additions & 4 deletions src/app/harbor/shop/shop-item-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import {
CardTitle,
} from '@/components/ui/card'
import { Button } from '@/components/ui/button'
import { useMemo } from 'react'
import React, { useMemo, useState } from 'react'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the React import?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Webstorm playing tricks again... fixed

import { cantAffordWords, purchaseWords, sample } from '../../../../lib/flavor'
import Icon from '@hackclub/icons'
import { transcript } from '../../../../lib/transcript'
import Modal from '@/components/ui/modal'
import Image from 'next/image'
const ActionArea = ({ item, filterIndex, affordable }) => {
const buyWord = useMemo(() => sample(purchaseWords), [item.id])
const getYourRacksUp = useMemo(() => sample(cantAffordWords), [item.id])
Expand Down Expand Up @@ -47,6 +49,8 @@ export const ShopItemComponent = ({
setFavouriteItems,
favouriteItems,
}) => {
let [detailsModal, setDetailsModal] = useState(false)

const cardHoverProps = {
whileHover: {
scale: 1.05,
Expand Down Expand Up @@ -89,9 +93,85 @@ export const ShopItemComponent = ({
})
}

const linkIndex = Number(filterIndex) - 1

return (
<motion.div {...cardHoverProps}>
<motion.div {...cardHoverProps} className="cursor-pointer">
<Modal isOpen={detailsModal} close={() => setDetailsModal(false)}>
<div className="flex flex-col max-h-[60vh] overflow-y-auto px-2 mb-5">
<h2 className="text-3xl">{item.name}</h2>
<h3
className="text-xl"
dangerouslySetInnerHTML={{ __html: item.subtitle }}
></h3>
<img
src={item.imageUrl}
alt={item.name}
className="max-w-sm mx-auto my-3"
/>

{item.description && (
<p
className="my-5"
dangerouslySetInnerHTML={{ __html: item.description }}
></p>
)}

<Image
src="/hr.svg"
className="w-2/3 mx-auto my-3"
alt=""
width={461}
height={11}
/>

{item.limited_qty && (
<i className="mt-3 text-amber-100">
This item is limited, buy it while you can!
</i>
)}

{item.fulfillment_description && (
<p
className="my-2 text-lg"
dangerouslySetInnerHTML={{ __html: item.fulfillment_description }}
></p>
)}

{item.links && linkIndex >= 0 && item.links[linkIndex] && (
<p>
We will most likely order it from{' '}
<a
className="underline"
target="_blank"
href={item.links[Number(filterIndex) - 1]}
>
this link
</a>
</p>
)}

{item.customs_likely && linkIndex !== 0 && (
<p className="font-bold italic text-xl">
Customs may apply outside of US!
</p>
)}
</div>

<Button
className="float-right mr-10"
onClick={() => setDetailsModal(false)}
>
Close
</Button>
</Modal>

<Card
onClick={(e) => {
if (e.target.tagName !== 'BUTTON' && e.target.tagName !== 'FORM') {
setDetailsModal(true)
}
}}
id={id}
className="h-full flex flex-col overflow-hidden shadow-lg transition-shadow duration-300 hover:shadow-xl"
>
Expand All @@ -116,7 +196,7 @@ export const ShopItemComponent = ({
height={20}
className="mr-1"
/>
{localPrice}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean to remove this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed it earlier to {filterIndex == 1 ? item.priceUs : item.priceGlobal} idk why, but reverted now

{filterIndex == 1 ? item.priceUs : item.priceGlobal}
</span>

{item.minimumHoursEstimated && item.maximumHoursEstimated ? (
Expand All @@ -133,7 +213,9 @@ export const ShopItemComponent = ({
<img
src={item.imageUrl}
alt={item.name}
onClick={() => {
onClick={(e) => {
e.stopPropagation()
setDetailsModal(false)
let interaction = transcript('item.base', {
name: item.name,
price: localPrice,
Expand Down
17 changes: 17 additions & 0 deletions src/app/harbor/shop/shop-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ export interface ShopItem {
outOfStock: boolean
minimumHoursEstimated: number
maximumHoursEstimated: number
description: string | null
customs_likely: boolean | null
fulfillment_description: string | null
links: string[] | null[]
limited_qty: boolean | null
}

export async function getShop(): Promise<ShopItem[]> {
Expand Down Expand Up @@ -80,6 +85,18 @@ export async function getShop(): Promise<ShopItem[]> {
maximumHoursEstimated: Number(
record.get('maximum_hours_estimated'),
),
description: record.get('description') as string | null,
customs_likely: Boolean(record.get('customs_likely')) as boolean,
fulfillment_description: record.get('fulfillment_description') as
| string
| null,
links: [
record.get('third_party_link_us') as string,
record.get('third_party_link_eu') as string,
record.get('third_party_link_in') as string,
record.get('third_party_link_ca') as string,
],
limited_qty: Boolean(record.get('limited_qty')) as boolean,
})
})

Expand Down
Loading