Skip to content

Commit

Permalink
Run prettier fix on all files (vercel#581)
Browse files Browse the repository at this point in the history
  • Loading branch information
goncy authored Nov 25, 2021
1 parent 96e9902 commit 73470c9
Show file tree
Hide file tree
Showing 74 changed files with 899 additions and 840 deletions.
4 changes: 2 additions & 2 deletions components/common/Layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ const FeatureBar = dynamic(
)

const Modal = dynamic(
() => import('@components/ui/Modal'),
Object.assign(dynamicProps, {ssr: false})
() => import('@components/ui/Modal'),
Object.assign(dynamicProps, { ssr: false })
)

interface Props {
Expand Down
11 changes: 9 additions & 2 deletions components/common/UserNav/UserNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,16 @@ const UserNav: FC<Props> = ({ className }) => {
<ul className={s.list}>
{process.env.COMMERCE_CART_ENABLED && (
<li className={s.item}>
<Button className={s.item} variant="naked" onClick={toggleSidebar} aria-label={`Cart items: ${itemsCount}`}>
<Button
className={s.item}
variant="naked"
onClick={toggleSidebar}
aria-label={`Cart items: ${itemsCount}`}
>
<Bag />
{itemsCount > 0 && <span className={s.bagCount}>{itemsCount}</span>}
{itemsCount > 0 && (
<span className={s.bagCount}>{itemsCount}</span>
)}
</Button>
</li>
)}
Expand Down
2 changes: 1 addition & 1 deletion components/product/Swatch/Swatch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const Swatch: React.FC<Omit<ButtonProps, 'variant'> & SwatchProps> = React.memo(
<Button
role="option"
aria-selected={active}
aria-label={(variant && label) ? `${variant} ${label}` : "Variant Swatch"}
aria-label={variant && label ? `${variant} ${label}` : 'Variant Swatch'}
className={swatchClassName}
{...(label && color && { title: label })}
style={color ? { backgroundColor: color } : {}}
Expand Down
2 changes: 1 addition & 1 deletion components/ui/Sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const Sidebar: FC<SidebarProps> = ({ children, onClose }) => {
}

const contentElement = contentRef.current

if (contentElement) {
disableBodyScroll(contentElement, { reserveScrollBarGap: true })
}
Expand Down
1 change: 0 additions & 1 deletion components/ui/Text/Text.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
@apply pt-1 pb-2 text-2xl font-bold tracking-wide cursor-pointer mb-2;
}


/* Apply base font sizes and styles for typography markup (h2, h2, ul, p, etc.).
A helpful addition for whenn page content is consumed from a source managed through a wysiwyg editor. */

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,33 @@ export const getLoggedInCustomerQuery = /* GraphQL */ `

export type Customer = NonNullable<GetLoggedInCustomerQuery['customer']>

const getLoggedInCustomer: CustomerEndpoint['handlers']['getLoggedInCustomer'] = async ({
req,
res,
config,
}) => {
const token = req.cookies[config.customerCookie]

if (token) {
const { data } = await config.fetch<GetLoggedInCustomerQuery>(
getLoggedInCustomerQuery,
undefined,
{
headers: {
cookie: `${config.customerCookie}=${token}`,
},
const getLoggedInCustomer: CustomerEndpoint['handlers']['getLoggedInCustomer'] =
async ({ req, res, config }) => {
const token = req.cookies[config.customerCookie]

if (token) {
const { data } = await config.fetch<GetLoggedInCustomerQuery>(
getLoggedInCustomerQuery,
undefined,
{
headers: {
cookie: `${config.customerCookie}=${token}`,
},
}
)
const { customer } = data

if (!customer) {
return res.status(400).json({
data: null,
errors: [{ message: 'Customer not found', code: 'not_found' }],
})
}
)
const { customer } = data

if (!customer) {
return res.status(400).json({
data: null,
errors: [{ message: 'Customer not found', code: 'not_found' }],
})

return res.status(200).json({ data: { customer } })
}

return res.status(200).json({ data: { customer } })
res.status(200).json({ data: null })
}

res.status(200).json({ data: null })
}

export default getLoggedInCustomer
6 changes: 3 additions & 3 deletions framework/bigcommerce/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export interface BigcommerceConfig extends CommerceAPIConfig {
storeChannelId?: string
storeUrl?: string
storeApiClientSecret?: string
storeHash?:string
storeHash?: string
storeApiFetch<T>(endpoint: string, options?: RequestInit): Promise<T>
}

Expand Down Expand Up @@ -81,8 +81,8 @@ const config: BigcommerceConfig = {
storeApiToken: STORE_API_TOKEN,
storeApiClientId: STORE_API_CLIENT_ID,
storeChannelId: STORE_CHANNEL_ID,
storeUrl:STORE_URL,
storeApiClientSecret:CLIENT_SECRET,
storeUrl: STORE_URL,
storeApiClientSecret: CLIENT_SECRET,
storeHash: STOREFRONT_HASH,
storeApiFetch: createFetchStoreApi(() => getCommerceApi().getConfig()),
}
Expand Down
27 changes: 14 additions & 13 deletions framework/bigcommerce/auth/use-login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ export const handler: MutationHook<LoginHook> = {
async fetcher({ input: { email, password }, options, fetch }) {
if (!(email && password)) {
throw new CommerceError({
message:
'An email and password are required to login',
message: 'An email and password are required to login',
})
}

Expand All @@ -25,16 +24,18 @@ export const handler: MutationHook<LoginHook> = {
body: { email, password },
})
},
useHook: ({ fetch }) => () => {
const { revalidate } = useCustomer()
useHook:
({ fetch }) =>
() => {
const { revalidate } = useCustomer()

return useCallback(
async function login(input) {
const data = await fetch({ input })
await revalidate()
return data
},
[fetch, revalidate]
)
},
return useCallback(
async function login(input) {
const data = await fetch({ input })
await revalidate()
return data
},
[fetch, revalidate]
)
},
}
24 changes: 13 additions & 11 deletions framework/bigcommerce/auth/use-logout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@ export const handler: MutationHook<LogoutHook> = {
url: '/api/logout',
method: 'GET',
},
useHook: ({ fetch }) => () => {
const { mutate } = useCustomer()
useHook:
({ fetch }) =>
() => {
const { mutate } = useCustomer()

return useCallback(
async function logout() {
const data = await fetch()
await mutate(null, false)
return data
},
[fetch, mutate]
)
},
return useCallback(
async function logout() {
const data = await fetch()
await mutate(null, false)
return data
},
[fetch, mutate]
)
},
}
24 changes: 13 additions & 11 deletions framework/bigcommerce/auth/use-signup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,18 @@ export const handler: MutationHook<SignupHook> = {
body: { firstName, lastName, email, password },
})
},
useHook: ({ fetch }) => () => {
const { revalidate } = useCustomer()
useHook:
({ fetch }) =>
() => {
const { revalidate } = useCustomer()

return useCallback(
async function signup(input) {
const data = await fetch({ input })
await revalidate()
return data
},
[fetch, revalidate]
)
},
return useCallback(
async function signup(input) {
const data = await fetch({ input })
await revalidate()
return data
},
[fetch, revalidate]
)
},
}
26 changes: 14 additions & 12 deletions framework/bigcommerce/cart/use-add-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,18 @@ export const handler: MutationHook<AddItemHook> = {

return data
},
useHook: ({ fetch }) => () => {
const { mutate } = useCart()
useHook:
({ fetch }) =>
() => {
const { mutate } = useCart()

return useCallback(
async function addItem(input) {
const data = await fetch({ input })
await mutate(data, false)
return data
},
[fetch, mutate]
)
},
}
return useCallback(
async function addItem(input) {
const data = await fetch({ input })
await mutate(data, false)
return data
},
[fetch, mutate]
)
},
}
34 changes: 18 additions & 16 deletions framework/bigcommerce/cart/use-cart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,24 @@ export const handler: SWRHook<GetCartHook> = {
url: '/api/cart',
method: 'GET',
},
useHook: ({ useData }) => (input) => {
const response = useData({
swrOptions: { revalidateOnFocus: false, ...input?.swrOptions },
})
useHook:
({ useData }) =>
(input) => {
const response = useData({
swrOptions: { revalidateOnFocus: false, ...input?.swrOptions },
})

return useMemo(
() =>
Object.create(response, {
isEmpty: {
get() {
return (response.data?.lineItems.length ?? 0) <= 0
return useMemo(
() =>
Object.create(response, {
isEmpty: {
get() {
return (response.data?.lineItems.length ?? 0) <= 0
},
enumerable: true,
},
enumerable: true,
},
}),
[response]
)
},
}),
[response]
)
},
}
38 changes: 18 additions & 20 deletions framework/bigcommerce/cart/use-remove-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,25 @@ export const handler = {
}: HookFetcherContext<RemoveItemHook>) {
return await fetch({ ...options, body: { itemId } })
},
useHook: ({ fetch }: MutationHookContext<RemoveItemHook>) => <
T extends LineItem | undefined = undefined
>(
ctx: { item?: T } = {}
) => {
const { item } = ctx
const { mutate } = useCart()
const removeItem: RemoveItemFn<LineItem> = async (input) => {
const itemId = input?.id ?? item?.id
useHook:
({ fetch }: MutationHookContext<RemoveItemHook>) =>
<T extends LineItem | undefined = undefined>(ctx: { item?: T } = {}) => {
const { item } = ctx
const { mutate } = useCart()
const removeItem: RemoveItemFn<LineItem> = async (input) => {
const itemId = input?.id ?? item?.id

if (!itemId) {
throw new ValidationError({
message: 'Invalid input used for this operation',
})
}
if (!itemId) {
throw new ValidationError({
message: 'Invalid input used for this operation',
})
}

const data = await fetch({ input: { itemId } })
await mutate(data, false)
return data
}
const data = await fetch({ input: { itemId } })
await mutate(data, false)
return data
}

return useCallback(removeItem as RemoveItemFn<T>, [fetch, mutate])
},
return useCallback(removeItem as RemoveItemFn<T>, [fetch, mutate])
},
}
Loading

0 comments on commit 73470c9

Please sign in to comment.