-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2634 from Hyperkid123/azure-flow-ms
[Stable] Azure flow ms
- Loading branch information
Showing
5 changed files
with
121 additions
and
91 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
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,37 @@ | ||
import { useLocation } from 'react-router-dom'; | ||
|
||
// TODO: Figure out what param chrome should expect | ||
export const AWS_BANNER_NAME = 'from-aws'; | ||
export const AZURE_BANNER_NAME = 'from-azure'; | ||
export const GCP_BANNER_NAME = 'from-gcp'; | ||
|
||
const partnerMapper: { [partner: string]: string } = { | ||
[AWS_BANNER_NAME]: 'AWS', | ||
[AZURE_BANNER_NAME]: 'Microsoft Azure', | ||
[GCP_BANNER_NAME]: 'Google Cloud', | ||
}; | ||
const possibleParams = [AWS_BANNER_NAME, AZURE_BANNER_NAME, GCP_BANNER_NAME]; | ||
|
||
const hasPartner = (params: URLSearchParams) => possibleParams.find((param) => params.has(param)); | ||
|
||
const removePartnerParam = (params: URLSearchParams) => { | ||
params.delete(AWS_BANNER_NAME); | ||
params.delete(AZURE_BANNER_NAME); | ||
params.delete(GCP_BANNER_NAME); | ||
return params; | ||
}; | ||
|
||
const useMarketplacePartner = () => { | ||
const { search } = useLocation(); | ||
|
||
const params = new URLSearchParams(search); | ||
const partnerId = hasPartner(params); | ||
const partner = partnerId ? partnerMapper[partnerId] : null; | ||
return { | ||
partner, | ||
partnerId, | ||
removePartnerParam: () => removePartnerParam(params), | ||
}; | ||
}; | ||
|
||
export default useMarketplacePartner; |