Skip to content

Commit

Permalink
Hotfix: Prevent cart count query if user details not present in OnRou…
Browse files Browse the repository at this point in the history
…teBCContext (#1798)

Co-authored-by: Chris Berg <chris.berg@aot-technologies.com>
Co-authored-by: Krishnan Subramanian <krishnan.s@aot-technologies.com>
  • Loading branch information
3 people authored Feb 6, 2025
1 parent e199376 commit 7e82642
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
id: release-name
run: |
echo release-name=$(curl https://api.github.com/repos/bcgov/onroutebc/releases/latest | jq -r .tag_name) >> $GITHUB_OUTPUT
echo release-num=V$(curl https://api.github.com/repos/bcgov/onroutebc/releases/latest | jq -r .tag_name | sed 's/[^0-9]//g') >> $GITHUB_OUTPUT
echo release-num=V$(curl https://api.github.com/repos/bcgov/onroutebc/releases/latest | jq -r .tag_name | sed 's/[^0-9.]//g') >> $GITHUB_OUTPUT
promote-images-release:
name: Promote Images - Release
needs: [vars]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { IDPS } from "../../types/idp";
import { LoadBCeIDUserContext } from "../LoadBCeIDUserContext";
import OnRouteBCContext from "../OnRouteBCContext";

const isBCeID = (identityProvider: string) => identityProvider === IDPS.BCEID;
const isBCeID = (identityProvider: string) => identityProvider === IDPS.BUSINESS_BCEID;

/**
* This component ensures that a page is only available to new BCeID users.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ export const CartContextProvider = ({
}: {
children?: React.ReactNode;
}) => {
const { companyId } = useContext(OnRouteBCContext);
const { companyId, userDetails, idirUserDetails } = useContext(OnRouteBCContext);
const doesUserDetailsExist = Boolean(userDetails) || Boolean(idirUserDetails);

// Set cart count for company
const cartCountQuery = useGetCartCount(
getDefaultRequiredVal(0, companyId),
doesUserDetailsExist,
);

const { data: fetchedCartCount } = cartCountQuery;
Expand Down
8 changes: 6 additions & 2 deletions frontend/src/features/permits/hooks/cart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,17 @@ export const useRemoveFromCart = () => {
/**
* Hook used to get the number of items in the cart.
* @param companyId id of company to get cart item count for
* @param doesUserDetailsExist Does the user details exist in the OnRouteBCContext
* @returns Query object used for getting cart item count
*/
export const useGetCartCount = (companyId: number) => {
export const useGetCartCount = (
companyId: number,
doesUserDetailsExist: boolean,
) => {
return useQuery({
queryKey: [CART_COUNT_KEY, companyId],
queryFn: () => getCartCount(companyId),
enabled: Boolean(companyId),
enabled: Boolean(companyId) && doesUserDetailsExist,
retry: false,
refetchOnMount: "always",
refetchOnWindowFocus: false,
Expand Down

0 comments on commit 7e82642

Please sign in to comment.