Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: phone country dropdown added #270

Merged
merged 57 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
7abe06a
feat: phone country dropdown added
Apr 3, 2024
4ba3fc7
style: style changes
Apr 3, 2024
e4f3b39
fix: get value of country code via recoil
Apr 3, 2024
35479ed
Merge branch 'main' into phone-number-validations
vsrivatsa-edinburgh Apr 4, 2024
1ff80b0
Merge branch 'main' into phone-number-validations
Apr 4, 2024
e1ad9aa
Merge branch 'main' into phone-number-validations
Apr 5, 2024
1ca3bc4
fix: phone country code comments addressed
Apr 5, 2024
dc2d030
fix: revert payment element
Apr 5, 2024
05ad185
fix: country code append
Apr 5, 2024
30a8add
Merge branch 'main' into phone-number-validations
Apr 9, 2024
412d1e4
feat: country options added
Apr 10, 2024
6b021ff
fix: map key
Apr 10, 2024
e18af17
Merge branch 'main' into phone-number-validations
Apr 10, 2024
49ba733
fix: belt functions removed
Apr 12, 2024
1c8dfa0
Merge branch 'main' of github.com:juspay/hyperswitch-web into phone-n…
Apr 14, 2024
39a0168
fix: dropdown changes added
Apr 15, 2024
3b1b776
Merge branch 'main' of github.com:juspay/hyperswitch-web into phone-n…
Apr 17, 2024
b3fc22d
Merge branch 'main' of github.com:juspay/hyperswitch-web into phone-n…
Apr 17, 2024
e000ee9
Merge branch 'main' into phone-number-validations
Apr 17, 2024
62ce705
Merge branch 'main' into phone-number-validations
Apr 18, 2024
c638e66
Merge branch 'main' into phone-number-validations
Apr 18, 2024
df49579
fix: comments addressed
Apr 18, 2024
d14006e
fix: comments addressed
Apr 18, 2024
162d704
fix: label comment addressed
Apr 18, 2024
f2c710c
Merge branch 'main' into phone-number-validations
Apr 18, 2024
f306c6a
fix: remove duplicate countries
Apr 19, 2024
10c3f3f
Merge branch 'phone-number-validations' of github.com:juspay/hyperswi…
Apr 19, 2024
5a77010
Merge branch 'main' into phone-number-validations
Apr 22, 2024
af61102
fix: comments addressed
Apr 23, 2024
762e20f
Merge branch 'phone-number-validations' of github.com:juspay/hyperswi…
Apr 23, 2024
1f754b6
fix: added breakpoints to debug
Apr 24, 2024
4c3df29
chore(release): 0.45.2 [skip ci]
semantic-release-bot Apr 24, 2024
32563dd
Merge branch 'main' into phone-number-validations
Apr 25, 2024
ca96770
fix: apple pay debugging (#333)
vsrivatsa-edinburgh Apr 25, 2024
f99edde
chore(release): 0.45.3 [skip ci]
semantic-release-bot Apr 25, 2024
34d4828
fix: apple pay debug
prafulkoppalkar Apr 25, 2024
43ccd89
chore(release): 0.45.4 [skip ci]
semantic-release-bot Apr 25, 2024
bc992df
fix: country code multiple same code fix
Apr 26, 2024
d47b822
Merge branch 'main' into phone-number-validations
Apr 26, 2024
6a737e2
fix: backgroundColor fix added
Apr 26, 2024
2af60e9
fix: spacing and only numeric char added
Apr 26, 2024
c6d5757
Merge branch 'main' of github.com:juspay/hyperswitch-web into phone-n…
Apr 29, 2024
dac50dc
fix: changelog updated
Apr 29, 2024
338d762
fix: revert elements changes
Apr 29, 2024
3ab4292
Merge branch 'main' into phone-number-validations
Apr 29, 2024
f3c1eba
Merge branch 'main' of github.com:juspay/hyperswitch-web into phone-n…
May 6, 2024
5c4a474
Merge branch 'main' into phone-number-validations
prafulkoppalkar May 6, 2024
c683854
fix: apple pay revert
May 6, 2024
7aea58c
fix: comments addressed
May 6, 2024
ec58ae6
Merge branch 'main' into phone-number-validations
prafulkoppalkar May 6, 2024
550294d
Merge branch 'main' into phone-number-validations
May 7, 2024
d5c6b4c
Merge branch 'main' into phone-number-validations
prafulkoppalkar May 8, 2024
38945c4
Merge branch 'main' into phone-number-validations
May 9, 2024
a49fa04
Merge branch 'main' into phone-number-validations
May 10, 2024
7b4195f
Merge branch 'main' of github.com:juspay/hyperswitch-web into phone-n…
May 10, 2024
288c04f
Merge branch 'phone-number-validations' of github.com:juspay/hyperswi…
May 10, 2024
d6f8ae7
Merge branch 'main' into phone-number-validations
prafulkoppalkar May 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Components/DropdownField.res
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ let make = (
~options,
~disabled=false,
~className="",
~width="w-full",
) => {
let {themeObj, localeString, config} = Recoil.useRecoilValueFromAtom(configAtom)
let {readOnly} = Recoil.useRecoilValueFromAtom(optionAtom)
Expand Down Expand Up @@ -45,7 +46,7 @@ let make = (

let cursorClass = !disabled ? "cursor-pointer" : "cursor-not-allowed"
<RenderIf condition={options->Array.length > 0}>
<div className="flex flex-col w-full">
<div className={`flex flex-col ${width}`}>
<RenderIf condition={fieldName->String.length > 0 && appearance.labels == Above}>
<div
className={`Label `}
Expand Down
21 changes: 19 additions & 2 deletions src/Components/PaymentField.res
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ open RecoilAtomTypes
let make = (
~setValue=?,
~value: RecoilAtomTypes.field,
~valueDropDown=?,
~setValueDropDown=?,
~dropDownFieldName=?,
~dropDownOptions=?,
~onChange,
~onBlur=?,
~rightIcon=React.null,
Expand Down Expand Up @@ -75,8 +79,21 @@ let make = (
}
let labelClass = getClassName("Label")
let inputClass = getClassName("Input")
let flexDirectionBasedOnType = type_ === "tel" ? "flex-row" : "flex-col"

<div className="flex flex-col w-full" style={ReactDOMStyle.make(~color=themeObj.colorText, ())}>
<div
className={`flex ${flexDirectionBasedOnType} w-full`}
style={ReactDOMStyle.make(~color=themeObj.colorText, ())}>
<RenderIf condition={type_ === "tel"}>
<DropdownField
appearance=config.appearance
value={valueDropDown->Option.getOr("")}
setValue={setValueDropDown->Option.getOr(_ => ())}
fieldName={dropDownFieldName->Option.getOr(fieldName)}
options={dropDownOptions->Option.getOr([])}
width="!w-1/3 mr-2"
PritishBudhiraja marked this conversation as resolved.
Show resolved Hide resolved
/>
</RenderIf>
<RenderIf condition={fieldName->String.length > 0 && config.appearance.labels == Above}>
<div
className={`Label ${labelClass}`}
Expand All @@ -90,7 +107,7 @@ let make = (
{React.string(fieldName)}
</div>
</RenderIf>
<div className="flex flex-row " style={ReactDOMStyle.make(~direction, ())}>
<div className="flex flex-row w-full" style={ReactDOMStyle.make(~direction, ())}>
<div className="relative w-full">
<input
style={ReactDOMStyle.make(
Expand Down
70 changes: 50 additions & 20 deletions src/Components/PhoneNumberPaymentInput.res
Original file line number Diff line number Diff line change
@@ -1,37 +1,64 @@
open RecoilAtoms
open PaymentType

@react.component
let make = () => {
open RecoilAtoms
open PaymentType
open Utils

let phoneRef = React.useRef(Nullable.null)
let {fields} = Recoil.useRecoilValueFromAtom(optionAtom)
let loggerState = Recoil.useRecoilValueFromAtom(loggerAtom)

let showDetails = getShowDetails(~billingDetails=fields.billingDetails, ~logger=loggerState)
let (phone, setPhone) = Recoil.useLoggedRecoilState(userPhoneNumber, "phone", loggerState)
let clientCountry = getClientCountry(CardUtils.dateTimeFormat().resolvedOptions().timeZone)
let currentCountryCode = Utils.getCountryCode(clientCountry.countryName)

let showDetails = getShowDetails(~billingDetails=fields.billingDetails, ~logger=loggerState)
let formatBSB = bsb => {
let formatted = bsb

let secondPart = formatted->String.sliceToEnd(~start=4)->String.trim

if formatted->String.length <= 4 {
"+351 "
} else if formatted->String.length > 4 {
`+351 ${secondPart}`
} else {
formatted
}
}
let countryAndCodeCodeList =
phoneNumberJson
->JSON.Decode.object
->Option.getOr(Dict.make())
->getArray("countries")

let phoneNumberCodeOptions = countryAndCodeCodeList->Array.reduce([], (acc, countryObj) => {
acc->Array.push(countryObj->getDictFromJson->getString("phone_number_code", ""))
acc
})

let defaultCountryCodeFilteredValue =
countryAndCodeCodeList
->Array.filter(countryObj => {
countryObj->getDictFromJson->getString("country_code", "") === currentCountryCode.isoAlpha2
})
->Array.get(0)
->Option.getOr(
{
"country_code": "",
PritishBudhiraja marked this conversation as resolved.
Show resolved Hide resolved
"phone_number_code": "",
"validation_regex": "",
"format_example": "",
"format_regex": "",
}->toJson,
)
->getDictFromJson
->getString("phone_number_code", "")

let (valueDropDown, setValueDropDown) = React.useState(_ => defaultCountryCodeFilteredValue)

let changePhone = ev => {
let val: string = ReactEvent.Form.target(ev)["value"]->String.replaceRegExp(%re("/\+D+/g"), "")
setPhone(prev => {
...prev,
value: val->formatBSB,
countryCode: valueDropDown,
value: val,
})
}

let phoneRef = React.useRef(Nullable.null)
React.useEffect(() => {
setPhone(prev => {
...prev,
countryCode: valueDropDown,
})
None
}, valueDropDown)

<RenderIf condition={showDetails.phone == Auto}>
<PaymentField
Expand All @@ -44,6 +71,9 @@ let make = () => {
inputRef=phoneRef
placeholder="+351 200 000 000"
maxLength=14
dropDownOptions=phoneNumberCodeOptions
valueDropDown
setValueDropDown
/>
</RenderIf>
}
1 change: 1 addition & 0 deletions src/Types/RecoilAtomTypes.res
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ type field = {
value: string,
isValid: option<bool>,
errorString: string,
countryCode?: string,
PritishBudhiraja marked this conversation as resolved.
Show resolved Hide resolved
}
3 changes: 2 additions & 1 deletion src/Utilities/RecoilAtoms.res
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ let userEmailAddress = Recoil.atom("userEmailAddress", defaultFieldValues)
let userPhoneNumber = Recoil.atom(
"userPhoneNumber",
{
value: "+351 ",
value: "",
isValid: None,
errorString: "",
countryCode: "",
},
)
let isGooglePayReady = Recoil.atom("isGooglePayReady", false)
Expand Down
Loading