-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: account item to page (#583) (#585)
* feat: click account item to page https://bigc-b2b.atlassian.net/browse/BUN-1266
- Loading branch information
1 parent
a0461f8
commit 884edd7
Showing
7 changed files
with
223 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
interface GotoPageByClickProps { | ||
href: string | ||
role: number | string | ||
isRegisterArrInclude: boolean | ||
} | ||
|
||
const hideAccountItems = [ | ||
'/account.php?action=view_returns', | ||
'/account.php?action=inbox', | ||
'/account.php?action=recent_items', | ||
] | ||
const accountTarget = [ | ||
{ | ||
originUrl: '/account.php?action=order_status', | ||
newTargetUrl: '/orders', | ||
}, | ||
{ | ||
originUrl: '/account.php?action=address_book', | ||
newTargetUrl: '/addresses', | ||
}, | ||
{ | ||
originUrl: '/account.php?action=account_details', | ||
newTargetUrl: '/accountSettings', | ||
}, | ||
] | ||
|
||
const removeBCMenus = () => { | ||
hideAccountItems.forEach((item: string) => { | ||
const itemNodes = document.querySelectorAll(`[href^="${item}"]`) | ||
|
||
if (itemNodes.length > 0) { | ||
itemNodes.forEach((node: CustomFieldItems) => { | ||
node.parentNode.remove() | ||
}) | ||
} | ||
}) | ||
} | ||
|
||
const redirectBcMenus = (key: string) => { | ||
let redirectUrl = '/orders' | ||
|
||
const currentItem: CustomFieldItems = | ||
accountTarget.find((item) => key.includes(item.originUrl)) || {} | ||
|
||
if (currentItem) { | ||
redirectUrl = currentItem?.newTargetUrl || '/orders' | ||
} | ||
|
||
return redirectUrl | ||
} | ||
|
||
const getCurrentLoginUrl = (href: string): string => { | ||
let url = '/login' | ||
if (typeof href !== 'string') return url | ||
if (href.includes('logout')) { | ||
url = '/login?loginFlag=3' | ||
} | ||
if (href?.includes('create_account')) { | ||
url = '/register' | ||
} | ||
|
||
return url | ||
} | ||
|
||
const gotoPageByClick = ({ | ||
href, | ||
role, | ||
isRegisterArrInclude, | ||
}: GotoPageByClickProps) => { | ||
const getUrl = redirectBcMenus(href) | ||
let newUrl = role === 3 ? '/dashboard' : getUrl | ||
|
||
if (getUrl === '/accountSettings') { | ||
newUrl = getUrl | ||
} | ||
|
||
const gotoUrl = isRegisterArrInclude ? getCurrentLoginUrl(href) : newUrl | ||
|
||
return gotoUrl | ||
} | ||
|
||
export { getCurrentLoginUrl, gotoPageByClick, redirectBcMenus, removeBCMenus } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters