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

OCP-1082: Category List View, OCP-1055: [WIP] Order Confirmation Page, OCP-1043: Breadcrumbs, OCP-1050: show SalePrice in Product Detail #38

Open
wants to merge 13 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
537 changes: 246 additions & 291 deletions apps/storefront/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/storefront/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-icons": "^5.2.1",
"react-router-dom": "^6.22.2",
"react-router-dom": "^6.26.2",
"universal-cookie": "^7.2.0"
},
"devDependencies": {
Expand Down
34 changes: 23 additions & 11 deletions apps/storefront/src/AppProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { FC, useCallback } from "react";
import routes from "./routes";
import { RouterProvider, createBrowserRouter } from "react-router-dom";
import { IOrderCloudErrorContext, OrderCloudProvider } from "@rwatt451/ordercloud-react";
import {
IOrderCloudErrorContext,
OrderCloudProvider,
} from "@rwatt451/ordercloud-react";
import {
ALLOW_ANONYMOUS,
BASE_API_URL,
Expand All @@ -12,6 +15,7 @@ import {
import { useToast } from "@chakra-ui/react";
import { OrderCloudError } from "ordercloud-javascript-sdk";
import GlobalLoadingIndicator from "./components/GlobalLoadingIndicator";
import { BreadCrumbItemsProvider } from "./hooks/useBreadcrumbItems";

const basename = import.meta.env.VITE_APP_CONFIG_BASE;

Expand All @@ -20,15 +24,22 @@ const router = createBrowserRouter(routes, { basename });
const AppProvider: FC = () => {
const toast = useToast();

const defaultErrorHandler = useCallback((error: OrderCloudError, {logout}:IOrderCloudErrorContext) => {
if (error.status === 401) {
console.log('DEFAULT ERROR HANDLER', 401)
return logout()
}
if (!toast.isActive(error.errorCode)) {
toast({ id: error.errorCode, title: error.status === 403 ? 'Permission denied' : error.message, status: "error" });
}
}, [toast])
const defaultErrorHandler = useCallback(
(error: OrderCloudError, { logout }: IOrderCloudErrorContext) => {
if (error.status === 401) {
console.log("DEFAULT ERROR HANDLER", 401);
return logout();
}
if (!toast.isActive(error.errorCode)) {
toast({
id: error.errorCode,
title: error.status === 403 ? "Permission denied" : error.message,
status: "error",
});
}
},
[toast]
);

return (
<OrderCloudProvider
Expand All @@ -39,8 +50,9 @@ const AppProvider: FC = () => {
allowAnonymous={ALLOW_ANONYMOUS}
defaultErrorHandler={defaultErrorHandler}
>
<BreadCrumbItemsProvider />
<RouterProvider router={router} />
<GlobalLoadingIndicator/>
<GlobalLoadingIndicator />
</OrderCloudProvider>
);
};
Expand Down
2 changes: 2 additions & 0 deletions apps/storefront/src/Layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { FC, useEffect } from "react";
import { Outlet, useLocation } from "react-router-dom";
import LoginModal from "../components/Login/LoginModal";
import MainMenu from "./MainMenu";
import Breadcrumbs from "../components/shared/Breadcrumbs";

const Layout: FC = () => {
const { pathname } = useLocation();
Expand All @@ -29,6 +30,7 @@ const Layout: FC = () => {
<>
<LoginModal disclosure={loginDisclosure} />
<MainMenu loginDisclosure={loginDisclosure} />
<Breadcrumbs/>
<VStack
alignItems="flex-start"
w="full"
Expand Down
4 changes: 2 additions & 2 deletions apps/storefront/src/Layout/MainMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const MainMenu: FC<MainMenuProps> = ({ loginDisclosure }) => {
key={catalog.ID}
onClick={() => setSelectedCatalog(catalog.ID || "")}
as={RouterLink}
to={`/shop/${selectedCatalog}/products`}
to={`/shop/${selectedCatalog}`}
>
{catalog.Name}
</MenuItem>
Expand All @@ -101,7 +101,7 @@ const MainMenu: FC<MainMenuProps> = ({ loginDisclosure }) => {
return (
<Button
as={RouterLink}
to={`/shop/${catalogs[0].ID}/products`}
to={`/shop/${catalogs[0].ID}`}
variant="ghost"
>
Shop All Products
Expand Down
2 changes: 1 addition & 1 deletion apps/storefront/src/Layout/MegaMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const MegaMenu: FC<MegaMenuProps> = ({
navigate(`/shop/${selectedCatalog}/categories/${categoryId}`);
onClose();
};

const handleViewAllCategoryClick = (categoryId: string | undefined) => {
if (!categoryId || !selectedCatalog) return;
navigate(`/shop/${selectedCatalog}/categories`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,20 @@ interface OcCurrentOrderLineItemListProps {
tabIndex?: number
}

const OcCurrentOrderLineItemList: FunctionComponent<OcCurrentOrderLineItemListProps> = ({
const OcCurrentOrderLineItemList: FunctionComponent<
OcCurrentOrderLineItemListProps
> = ({
emptyMessage,
editable,
productType,
lineItems,
onChange,
tabIndex
}) => {
let productItems = lineItems
let productItems = lineItems;
if (productType != null) {
productItems = lineItems?.filter(function (p) {
return p.xp?.Type == productType
})
return p.xp?.Type == productType;
});
}

return (
Expand All @@ -32,9 +33,8 @@ const OcCurrentOrderLineItemList: FunctionComponent<OcCurrentOrderLineItemListPr
editable={editable}
lineItems={productItems}
onChange={onChange}
tabIndex={tabIndex}
/>
)
}
);
};

export default OcCurrentOrderLineItemList
11 changes: 4 additions & 7 deletions apps/storefront/src/components/cart/OcLineItemCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,24 @@ import React, {
useState,
} from "react";
import { TbPhoto } from "react-icons/tb";
import { Link as RouterLink } from "react-router-dom";
import { Link as RouterLink, useLocation } from "react-router-dom";
import useDebounce from "../../hooks/useDebounce";
import formatPrice from "../../utils/formatPrice";
import OcQuantityInput from "./OcQuantityInput";
import { TABS } from "./ShoppingCart";

interface OcLineItemCardProps {
lineItem: LineItem;
editable?: boolean;
onChange?: (newLi: LineItem) => void;
tabIndex?: number;
}

const OcLineItemCard: FunctionComponent<OcLineItemCardProps> = ({
lineItem,
editable,
onChange,
tabIndex,
}) => {
const [quantity, _setQuantity] = useState(lineItem.Quantity);

const { pathname } = useLocation();
const debouncedQuantity: number = useDebounce(quantity, 300);

const product = useMemo(() => lineItem.Product, [lineItem]);
Expand Down Expand Up @@ -116,7 +113,7 @@ const OcLineItemCard: FunctionComponent<OcLineItemCardProps> = ({
position="absolute"
/>
</Center>
{tabIndex !== TABS.CONFIRMATION && (
{pathname !== "/order-confirmation" && (
<Button
size="xs"
fontSize=".75rem"
Expand All @@ -128,7 +125,7 @@ const OcLineItemCard: FunctionComponent<OcLineItemCardProps> = ({
)}
</VStack>
<VStack alignItems="flex-start" gap={3} flexGrow="1">
<Link as={RouterLink} to={`/products/${lineItem?.Product?.ID}`}>
<Link as={RouterLink} to={`/shop/${lineItem?.Product?.ID}`}>
<Text fontSize="sm" lineHeight="1.3" display="inline-block">
{lineItem.Product?.Name}
</Text>
Expand Down
3 changes: 0 additions & 3 deletions apps/storefront/src/components/cart/OcLineItemList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ interface OcLineItemListProps {
editable?: boolean;
lineItems?: LineItem[];
onChange: (newLineItem: LineItem) => void;
tabIndex?: number;
}

const OcLineItemList: FunctionComponent<OcLineItemListProps> = ({
emptyMessage,
editable,
lineItems,
onChange,
tabIndex
}) => {
return lineItems && lineItems.length ? (
<VStack gap={6} alignItems="flex-start" w="full">
Expand All @@ -35,7 +33,6 @@ const OcLineItemList: FunctionComponent<OcLineItemListProps> = ({
lineItem={li}
editable={editable}
onChange={onChange}
tabIndex={tabIndex}
/>
))}
</CardBody>
Expand Down
18 changes: 7 additions & 11 deletions apps/storefront/src/components/cart/OcQuantityInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ interface OcQuantityInputProps {
disabled?: boolean
quantity: number
onChange: (quantity: number) => void
size?: string;
}

const OcQuantityInput: FunctionComponent<OcQuantityInputProps> = ({
Expand All @@ -30,6 +31,7 @@ const OcQuantityInput: FunctionComponent<OcQuantityInputProps> = ({
disabled,
quantity,
onChange,
size
}) => {

const [ps, setPs] = useState(priceSchedule);
Expand Down Expand Up @@ -60,34 +62,28 @@ const OcQuantityInput: FunctionComponent<OcQuantityInputProps> = ({
}

return ps ? (
<VStack
alignItems="flex-start"
gap={0}
>
<VStack alignItems="flex-start" gap={0}>
{/* <FormLabel>{label}</FormLabel> */}
{ps?.RestrictedQuantity ? (
<Select
maxW="100"
size="sm"
size={size || "sm"}
id={controlId}
isDisabled={disabled}
value={quantity}
onChange={handleSelectChange}
>
{ps.PriceBreaks?.map((pb) => (
<option
key={pb.Quantity}
value={pb.Quantity}
>
<option key={pb.Quantity} value={pb.Quantity}>
{pb.Quantity}
</option>
))}
</Select>
) : (
<NumberInput
maxW="100"
size="sm"
value={quantity || ''}
size={size || "sm"}
value={quantity || ""}
defaultValue={quantity}
onChange={handleNumberInputChange}
isDisabled={disabled}
Expand Down
Loading