Skip to content

Commit

Permalink
B2B-2150 - move more business logic and data fetching into useData wi…
Browse files Browse the repository at this point in the history
…thin ShoppingLists (#238)
  • Loading branch information
leeBigCommerce authored Feb 5, 2025
1 parent ff44a75 commit d83aab7
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions apps/storefront/src/pages/ShoppingLists/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,18 @@ function useData() {
useAppSelector(rolePermissionSelector);
const companyId = companyB2BId || salesRepCompanyId;

const deleteShoppingList = isB2BUser ? deleteB2BShoppingList : deleteBcShoppingList;

const getUserShoppingLists = isB2BUser
? () => getShoppingListsCreatedByUser(Number(companyId), 1)
: () => Promise.resolve({});

return {
companyId,
isB2BUser,
shoppingListCreateActionsPermission,
submitShoppingListPermission,
deleteShoppingList,
getUserShoppingLists,
};
}

Expand All @@ -54,10 +61,11 @@ function ShoppingLists() {
const [paginationTableRef] = useTableRef();

const {
companyId,
isB2BUser,
shoppingListCreateActionsPermission,
submitShoppingListPermission,
deleteShoppingList,
getUserShoppingLists,
} = useData();

const {
Expand All @@ -67,9 +75,7 @@ function ShoppingLists() {

useEffect(() => {
const initFilter = async () => {
const createdByUsers = isB2BUser
? await getShoppingListsCreatedByUser(Number(companyId), 1)
: {};
const createdByUsers = await getUserShoppingLists();

const filterInfo = getFilterMoreList(createdByUsers, submitShoppingListPermission);

Expand Down Expand Up @@ -207,13 +213,8 @@ function ShoppingLists() {
try {
setIsRequestLoading(true);
handleCancelClick();
const id: number = deleteItem?.id || 0;

if (isB2BUser) {
await deleteB2BShoppingList(id);
} else {
await deleteBcShoppingList(id);
}
await deleteShoppingList(deleteItem?.id || 0);

snackbar.success(b3Lang('shoppingLists.deleteSuccess'));
} finally {
Expand Down

0 comments on commit d83aab7

Please sign in to comment.