Skip to content

Commit

Permalink
type updates
Browse files Browse the repository at this point in the history
  • Loading branch information
dustinfirman committed Apr 1, 2024
1 parent 39b231e commit 452b690
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
8 changes: 6 additions & 2 deletions examples/b2b/app/components/Header.tsx
Expand Up @@ -4,6 +4,10 @@ import {useState, Suspense} from 'react';
import type {HeaderQuery} from 'storefrontapi.generated';
import type {LayoutProps} from './Layout';
import {useRootLoaderData} from '~/root';
import type {
CompanyLocation,
CompanyLocationConnection,
} from '@shopify/hydrogen-react/customer-account-api-types';

/***********************************************/
/********** EXAMPLE UPDATE STARTS ************/
Expand Down Expand Up @@ -156,7 +160,7 @@ function CartToggle({cart}: Pick<HeaderProps, 'cart'>) {
/********** EXAMPLE UPDATE STARTS ************/
function LocationDropdown({company}: Pick<HeaderProps, 'company'>) {
const locations = company?.locations?.edges
? company.locations.edges.map((location) => {
? company.locations.edges.map((location: CompanyLocationConnection) => {
return {...location.node};
})
: [];
Expand Down Expand Up @@ -187,7 +191,7 @@ function LocationDropdown({company}: Pick<HeaderProps, 'company'>) {
value={selectedLocation}
style={{marginRight: '4px'}}
>
{locations.map((location) => {
{locations.map((location: CompanyLocation) => {
return (
<option
defaultValue={selectedLocation}
Expand Down
7 changes: 4 additions & 3 deletions examples/b2b/app/components/LocationSelector.tsx
Expand Up @@ -2,12 +2,13 @@ import {CartForm} from '@shopify/hydrogen';
import type {
Company,
CompanyLocation,
CompanyLocationConnection,
} from '@shopify/hydrogen-react/customer-account-api-types';

export function LocationSelector({company}: {company: Company}) {
const locations = company?.locations?.edges
? company.locations.edges.map((loc) => {
return {...loc.node};
? company.locations.edges.map((location: CompanyLocationConnection) => {
return {...location.node};
})
: [];

Expand Down Expand Up @@ -42,7 +43,7 @@ export function LocationSelector({company}: {company: Company}) {
<CartForm route="/cart" action={CartForm.ACTIONS.BuyerIdentityUpdate}>
<fieldset>
<legend>Choose a location:</legend>
{locations.map((location) => {
{locations.map((location: CompanyLocation) => {
return (
<div key={location.id}>
<LocationItem location={location} />
Expand Down
4 changes: 3 additions & 1 deletion examples/b2b/app/routes/cart.tsx
Expand Up @@ -5,6 +5,7 @@ import {CartForm} from '@shopify/hydrogen';
import {json, type ActionFunctionArgs} from '@shopify/remix-oxygen';
import {CartMain} from '~/components/Cart';
import {useRootLoaderData} from '~/root';
import type {CartBuyerIdentityInput} from '@shopify/hydrogen/storefront-api-types';

export const meta: MetaFunction = () => {
return [{title: `Hydrogen | Cart`}];
Expand All @@ -20,7 +21,8 @@ export async function action({request, context}: ActionFunctionArgs) {
/***********************************************/
/********** EXAMPLE UPDATE STARTS ************/

const companyLocationId = inputs.companyLocationId as string; // fix this type properly
const companyLocationId =
inputs.companyLocationId as CartBuyerIdentityInput['companyLocationId'];

if (companyLocationId) {
context.customerAccount.UNSTABLE_setBuyer({companyLocationId});
Expand Down

0 comments on commit 452b690

Please sign in to comment.