Skip to content

Commit

Permalink
linted and fmted
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-at-mit committed Jan 14, 2025
1 parent f6ae402 commit 1a709bf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
22 changes: 14 additions & 8 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ type CartProps = {

type CartBodyProps = {
systemId: number;
cartItems: BasketItemWithProduct[];
};

const SelectSystemContainer = styled.div`
Expand All @@ -50,7 +49,7 @@ const ProductListContainer = styled.div`
const SelectSystem: React.FC = () => {
const systems = useMetaIntegratedSystemsList();
const router = useRouter();

const [_selectedSystem, setSelectedSystem] = useState<string | null>(null);
const hndSystemChange = (ev: React.ChangeEvent<HTMLSelectElement>) => {
setSelectedSystem(ev.target.value);
router.push(`/?system=${ev.target.value}`);
Expand Down Expand Up @@ -149,14 +148,21 @@ const Cart: React.FC<CartProps> = ({ system }) => {
const [refreshKey, setRefreshKey] = useState(0);

const addToCart = async () => {
const selectedProduct = products.data.results.find(
(product: Product) => product.id === selectedProductId,
);
const selectedProduct =
products &&
products.data &&
products.data.results.find(
(product: Product) => product.id === selectedProductId,
);

if (!selectedProduct) {
return;
}

try {
const response = await createBasketFromProduct.mutateAsync({
sku: selectedProduct.sku,
system_slug: selectedSystem?.slug,
system_slug: selectedSystem?.slug ?? "",
});

if (response && response.id) {
Expand All @@ -166,7 +172,7 @@ const Cart: React.FC<CartProps> = ({ system }) => {
console.error("Failed to add product to cart", error);
}
};

console.log(products.data);
return (
selectedSystem &&
products.isFetched &&
Expand All @@ -180,7 +186,7 @@ const Cart: React.FC<CartProps> = ({ system }) => {
onChange={(e) => setSelectedProductId(Number(e.target.value))}
>
<option value="">Select a product</option>
{products.data.results.map((product: Product) => (
{products.data.results.map((product) => (
<option key={product.id} value={product.id}>
{product.name}
</option>
Expand Down
10 changes: 7 additions & 3 deletions src/services/ecommerce/payments/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,18 @@ const usePaymentsBasketList = (
...opts,
});

const usePaymentsBasketRetrieve = (id: number, opts: ExtraQueryOpts = {}) => {
const usePaymentsBasketRetrieve = (
id: number,
opts: ExtraQueryOpts & { queryKey?: UseQueryOptions["queryKey"] } = {},
) => {
const { queryKey, ...restOpts } = opts; // Destructure queryKey from opts
return useQuery({
queryKey: ["paymentsBaskets", id],
queryKey: queryKey || ["paymentsBaskets", id], // Use queryKey from opts or default
queryFn: async () => {
const response = await paymentsApi.paymentsBasketsRetrieve({ id });
return response.data;
},
...opts,
...restOpts, // Spread the remaining options
});
};

Expand Down

0 comments on commit 1a709bf

Please sign in to comment.