-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(PAYMENTS-18631): add country selector
- Loading branch information
Showing
10 changed files
with
217 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { Country } from './country.interface'; | ||
|
||
export interface CountryResponse { | ||
countryList: Country[]; | ||
} |
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,5 @@ | ||
export interface Country { | ||
ISO: string; | ||
aliases: null | string; | ||
name: string; | ||
} |
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,20 @@ | ||
import { Message } from '../../core/message.interface'; | ||
import { isEventMessage } from './event-message.guard'; | ||
import { EventName } from '../../core/event-name.enum'; | ||
import { CountryResponse } from '../country-response.interface'; | ||
|
||
export const isCountryListEventMessage = ( | ||
messageData: unknown, | ||
): messageData is Message<{ | ||
countryList: CountryResponse['countryList']; | ||
currentCountry: string; | ||
}> => { | ||
if (isEventMessage(messageData)) { | ||
return ( | ||
messageData.name === EventName.getCountryList && | ||
(messageData.data as { [key: string]: unknown })?.countryList !== | ||
undefined | ||
); | ||
} | ||
return false; | ||
}; |
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
29 changes: 29 additions & 0 deletions
29
src/features/headless-checkout/post-messages-handlers/get-country-list.handler.ts
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,29 @@ | ||
import { Handler } from '../../../core/post-messages-client/handler.type'; | ||
import { Message } from '../../../core/message.interface'; | ||
import { CountryResponse } from '../../../core/country-response.interface'; | ||
import { isCountryListEventMessage } from '../../../core/guards/country-list-event-message.guard'; | ||
|
||
export const getCountryListHandler: Handler<{ | ||
countryList: CountryResponse['countryList']; | ||
currentCountry: string; | ||
}> = ( | ||
message: Message, | ||
): { | ||
isHandled: boolean; | ||
value: { | ||
countryList: CountryResponse['countryList']; | ||
currentCountry: string; | ||
}; | ||
} | null => { | ||
if (!isCountryListEventMessage(message)) { | ||
return null; | ||
} | ||
|
||
const countryList = message.data?.countryList ?? []; | ||
const currentCountry = message.data?.currentCountry ?? ''; | ||
|
||
return { | ||
isHandled: true, | ||
value: { countryList, currentCountry }, | ||
}; | ||
}; |
1 change: 1 addition & 0 deletions
1
src/features/headless-checkout/web-components/select/select-attributes.enum.ts
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export enum SelectAttributes { | ||
name = 'name', | ||
type = 'type', | ||
} |
4 changes: 4 additions & 0 deletions
4
src/features/headless-checkout/web-components/select/select-type.enum.ts
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,4 @@ | ||
export enum SelectType { | ||
country = 'country', | ||
formControl = 'form-control', | ||
} |
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
Oops, something went wrong.