Skip to content

Commit

Permalink
feat: buttonTypes
Browse files Browse the repository at this point in the history
  • Loading branch information
manideepk90 committed Feb 13, 2025
1 parent 17147df commit 832e217
Showing 1 changed file with 17 additions and 39 deletions.
56 changes: 17 additions & 39 deletions src/types/NetceteraCustomisationType.res
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type toolbarCustomization = {
}

type buttonCustomization = {
buttonType: string,
backgroundColor?: string,
cornerRadius?: float,
textFontSize?: float,
Expand All @@ -34,8 +35,7 @@ type netceteraChallengeUICustomization = {
labelCustomization?: labelCustomization,
textBoxCustomization?: textBoxCustomization,
toolbarCustomization?: toolbarCustomization,
submitButtonCustomization?: buttonCustomization,
cancelButtonCustomization?: buttonCustomization,
buttonCustomization?: array<buttonCustomization>,
viewCustomization?: viewCustomization,
}

Expand Down Expand Up @@ -81,39 +81,18 @@ let fun = netceteraChallengeUICustomization => {
None
}

let buttonObj = getObj(uiObj, "buttonCustomization", Dict.make())

let submitButtonCustomization = if buttonObj != Dict.make() {
let submitBtn = getObj(buttonObj, "submit", Dict.make())
if submitBtn != Dict.make() {
Some({
backgroundColor: ?getOptionString(submitBtn, "backgroundColor"),
cornerRadius: ?getOptionFloat(submitBtn, "cornerRadius"),
textFontSize: ?getOptionFloat(submitBtn, "textFontSize"),
textColor: ?getOptionString(submitBtn, "textColor"),
})
} else {
None
}
} else {
None
}
let buttonCustomization = getArrayFromDict(uiObj, "buttonCustomization", [])
let buttonCustomizationArray = buttonCustomization->Array.map(obj => {
let objDict = getDictFromJson(obj)
({
buttonType: getOptionString(objDict, "buttonType")->Option.getOr("SUBMIT"),
backgroundColor: ?getOptionString(objDict, "backgroundColor"),
cornerRadius: ?getOptionFloat(objDict, "cornerRadius"),
textFontSize: ?getOptionFloat(objDict, "textFontSize"),
textColor: ?getOptionString(objDict, "textColor"),
})
})

let cancelButtonCustomization = if buttonObj != Dict.make() {
let cancelBtn = getObj(buttonObj, "cancel", Dict.make())
if cancelBtn != Dict.make() {
Some({
backgroundColor: ?getOptionString(cancelBtn, "backgroundColor"),
cornerRadius: ?getOptionFloat(cancelBtn, "cornerRadius"),
textFontSize: ?getOptionFloat(cancelBtn, "textFontSize"),
textColor: ?getOptionString(cancelBtn, "textColor"),
})
} else {
None
}
} else {
None
}

let viewObj = getObj(uiObj, "viewCustomization", Dict.make())
let viewCustomization = if viewObj != Dict.make() {
Expand All @@ -129,8 +108,7 @@ let fun = netceteraChallengeUICustomization => {
?labelCustomization,
?textBoxCustomization,
?toolbarCustomization,
?submitButtonCustomization,
?cancelButtonCustomization,
buttonCustomization : buttonCustomizationArray,
?viewCustomization,
}

Expand All @@ -140,7 +118,7 @@ let fun = netceteraChallengeUICustomization => {
}

let getChallengeCustomisationRecord = (netceteraChallengeUICustomizationDict, locale) => {
let locale = locale->Option.getOr("")
let locale = locale->Option.getOr("en")
let lightModeDict =
netceteraChallengeUICustomizationDict
->Option.getOr(Dict.make())
Expand All @@ -153,12 +131,12 @@ let getChallengeCustomisationRecord = (netceteraChallengeUICustomizationDict, lo
->Dict.get("darkModeCustomization")
->Option.flatMap(JSON.Decode.object)

Console.log2("LightMode", lightModeDict)
// Console.log2("LightMode", lightModeDict)

let lightX = fun(lightModeDict)
let darkX = fun(darkModeDict)

Console.log2("LightMode X", lightX)
// Console.log2("LightMode X", lightX)

{locale, lightMode: lightX, darkMode: darkX}
}

0 comments on commit 832e217

Please sign in to comment.