Skip to content

Commit

Permalink
refactor: Common file for all identity functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Pritish Budhiraja committed Dec 11, 2023
1 parent f5363b4 commit 6a51261
Show file tree
Hide file tree
Showing 50 changed files with 136 additions and 171 deletions.
34 changes: 17 additions & 17 deletions config/FeatureFlag.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{
"test_live_toggle": false,
"test_live_toggle": true,
"is_live_mode": false,
"magic_link": false,
"production_access": false,
"quick_start": false,
"switch_merchant": false,
"audit_trail": false,
"system_metrics": false,
"sample_data": false,
"frm": false,
"payout": false,
"recon": false,
"user_management": false,
"magic_link": true,
"production_access": true,
"quick_start": true,
"switch_merchant": true,
"audit_trail": true,
"system_metrics": true,
"sample_data": true,
"frm": true,
"payout": true,
"recon": true,
"user_management": true,
"test_processors": true,
"feedback": false,
"verify_connector": false,
"feedback": true,
"verify_connector": true,
"mixpanel": false,
"business_profile": false,
"generate_report": false,
"forgot_password": false,
"business_profile": true,
"generate_report": true,
"forgot_password": true,
"oss_build": true
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ let make = (
endDateArr->Belt.Array.get(i)->Belt.Option.getWithDefault(x),
))

input.onChange(newArr->NestedDropdown.formToArray)
input.onChange(newArr->Identity.anyTypeToReactEvent)
}

let showCalendars = React.useMemo1(() => {
Expand Down
9 changes: 4 additions & 5 deletions src/components/Base64ImageInputWithDnD.res
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
external toReactEvent: 'a => ReactEvent.Form.t = "%identity"
external strToDomImg: string => Webapi.Dom.Image.t = "%identity"
@send external drawImage: (Webapi.Canvas.Canvas2d.t, 'a, int, int) => unit = "drawImage"
@send external toDataURL: 'a => string = "toDataURL"
Expand Down Expand Up @@ -57,7 +56,7 @@ let make = (
)
let clearImage = _evt => {
setFilename(_ => "")
input.onChange(""->toReactEvent)
input.onChange(""->Identity.stringToFormReactEvent)
}
let onChange = evt => {
let target = ReactEvent.Form.target(evt)
Expand All @@ -76,7 +75,7 @@ let make = (
let target = ReactEvent.Form.target(e)
let data = target["result"]
setIsNewUpload(_ => true)
input.onChange(toReactEvent(data))
input.onChange(data->Identity.anyTypeToReactEvent)
}
}
}
Expand Down Expand Up @@ -106,7 +105,7 @@ let make = (
context->drawImage(img, 0, 0)
toDataURL(canvas)
}
input.onChange(a->toReactEvent)
input.onChange(a->Identity.stringToFormReactEvent)
}
<div
onDragOver={ev => {
Expand All @@ -129,7 +128,7 @@ let make = (
let target = ReactEvent.Form.target(e)
let data = target["result"]
setIsNewUpload(_ => true)
input.onChange(toReactEvent(data))
input.onChange(data->Identity.anyTypeToReactEvent)
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/components/CsvFileUpload.res
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
external toReactEvent: 'a => ReactEvent.Form.t = "%identity"
type t

type formData
Expand Down Expand Up @@ -28,7 +27,7 @@ let make = (
setFilenameVal(_ => "")
onFileUpload(None)

input.onChange(""->toReactEvent)
input.onChange(""->Identity.stringToFormReactEvent)
}

let onChange = evt => {
Expand Down
9 changes: 4 additions & 5 deletions src/components/CsvInputField.res
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
external toReactEvent: 'a => ReactEvent.Form.t = "%identity"
external jsonToarr: Js.Json.t => array<'a> = "%identity"
external arrToReactEvent: array<string> => ReactEvent.Form.t = "%identity"
external strToReactEvent: string => ReactEvent.Form.t = "%identity"
Expand All @@ -7,7 +6,7 @@ module FilenameSaver = {
@react.component
let make = (~input: ReactFinalForm.fieldRenderPropsInput, ~fileName) => {
React.useEffect1(() => {
let reactEvFilename = fileName->toReactEvent
let reactEvFilename = fileName->Identity.anyTypeToReactEvent
input.onChange(reactEvFilename)
None
}, [fileName])
Expand Down Expand Up @@ -164,7 +163,7 @@ let make = (
})

if errorLines->Js.Array2.length === 0 {
input.onChange(toReactEvent(res))
input.onChange(res->Identity.anyTypeToReactEvent)
toast("File Uploaded Successfully", ToastSuccess)
}

Expand All @@ -175,7 +174,7 @@ let make = (
}

| None => {
input.onChange(toReactEvent(res))
input.onChange(res->Identity.anyTypeToReactEvent)
toast("File Uploaded Successfully", ToastSuccess)
}
}
Expand All @@ -188,7 +187,7 @@ let make = (
}
| _ =>
setIsNewUpload(_ => true)
input.onChange(toReactEvent(csv))
input.onChange(csv->Identity.anyTypeToReactEvent)
toast("File Uploaded Successfully", ToastSuccess)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/DatePicker.res
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
external strToForm: string => ReactEvent.Form.t = "%identity"
external jsonToForm: Js.Json.t => ReactEvent.Form.t = "%identity"
external formEvAsString: ReactEvent.Form.t => string = "%identity"

@react.component
let make = (
~input: ReactFinalForm.fieldRenderPropsInput,
Expand Down Expand Up @@ -167,7 +167,7 @@ let make = (
name: "string",
onBlur: _ev => (),
onChange: timeValEv => {
let timeVal = timeValEv->formEvAsString
let timeVal = timeValEv->Identity.formReactEventToString
if selectedDate !== "" {
let todayDayJsObj = Js.Date.make()->Js.Date.toString->DayJs.getDayJsForString
let todayTime = todayDayJsObj.format(. "HH:mm:ss")
Expand Down
5 changes: 2 additions & 3 deletions src/components/DateRangePicker.res
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
external strToForm: string => ReactEvent.Form.t = "%identity"
external formEvAsString: ReactEvent.Form.t => string = "%identity"

let defaultCellHighlighter = (_): Calendar.highlighter => {
{
Expand Down Expand Up @@ -458,7 +457,7 @@ module Base = {
name: "string",
onBlur: _ev => (),
onChange: timeValEv => {
let startTimeVal = timeValEv->formEvAsString
let startTimeVal = timeValEv->Identity.formReactEventToString
let endTime = localEndDate->getTimeStringForValue(isoStringToCustomTimeZone)

if localStartDate !== "" {
Expand All @@ -481,7 +480,7 @@ module Base = {
name: "string",
onBlur: _ev => (),
onChange: timeValEv => {
let endTimeVal = timeValEv->formEvAsString
let endTimeVal = timeValEv->Identity.formReactEventToString
let startTime = localStartDate->getTimeStringForValue(isoStringToCustomTimeZone)
if localEndDate !== "" {
if disableFutureDates && selectedEndDate == todayDate && endTimeVal > todayTime {
Expand Down
3 changes: 1 addition & 2 deletions src/components/DistributionDonut/DistributionDonut.res
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
external objToJson: {..} => Js.Json.t = "%identity"
external formEventToStr: ReactEvent.Form.t => string = "%identity"

type dataPoint = {y: int, name: string}

Expand Down Expand Up @@ -160,7 +159,7 @@ let make = (
let filterInput: ReactFinalForm.fieldRenderPropsInput = {
name: "Get By",
onBlur: _ev => (),
onChange: ev => {setGroupBy(_ => ev->formEventToStr)},
onChange: ev => {setGroupBy(_ => ev->Identity.formReactEventToString)},
onFocus: _ev => (),
value: groupBy->Js.Json.string,
checked: true,
Expand Down
4 changes: 1 addition & 3 deletions src/components/DraggableFilter.res
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ type rec options = {
options: option<array<options>>,
}

external formToArray: 'a => ReactEvent.Form.t = "%identity"

module TypeText = {
@react.component
let make = () => {
Expand Down Expand Up @@ -429,7 +427,7 @@ let make = (
}

React.useEffect1(() => {
input.onChange(dataSelectedBase->formToArray)
input.onChange(dataSelectedBase->Identity.anyTypeToReactEvent)
None
}, [dataSelectedBase])
let keyExtractor = (index, data, isDragging) => {
Expand Down
13 changes: 9 additions & 4 deletions src/components/DynamicChart.res
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,6 @@ let useChartFetch = (~setStatusDict) => {
fetchChartData
}

external formEventToStr: ReactEvent.Form.t => string = "%identity"
external tofloat: string => float = "%identity"

let granularityMapper = (granularity: granularity) => {
Expand Down Expand Up @@ -862,7 +861,9 @@ let make = (
let _inputChart: ReactFinalForm.fieldRenderPropsInput = {
name: "inputChart",
onChange: ev => {
updateChartCompFilters(Js.Dict.fromArray([("chartType", ev->formEventToStr)]))
updateChartCompFilters(
Js.Dict.fromArray([("chartType", ev->Identity.formReactEventToString)]),
)
},
value: chartTypeFromUrl->Js.Json.string,
onBlur: _ev => (),
Expand All @@ -872,7 +873,9 @@ let make = (
let inputMetricTop: ReactFinalForm.fieldRenderPropsInput = {
name: "inputMetricTop",
onChange: ev => {
updateChartCompFilters(Js.Dict.fromArray([("chartTopMetric", ev->formEventToStr)]))
updateChartCompFilters(
Js.Dict.fromArray([("chartTopMetric", ev->Identity.formReactEventToString)]),
)
},
value: chartTopMetricFromUrl->Js.Json.string,
onBlur: _ev => (),
Expand All @@ -882,7 +885,9 @@ let make = (
let inputMetricBottom: ReactFinalForm.fieldRenderPropsInput = {
name: "inputMetricBottom",
onChange: ev => {
updateChartCompFilters(Js.Dict.fromArray([("chartBottomMetric", ev->formEventToStr)]))
updateChartCompFilters(
Js.Dict.fromArray([("chartBottomMetric", ev->Identity.formReactEventToString)]),
)
},
value: chartBottomMetricFromUrl->Js.Json.string,
onBlur: _ev => (),
Expand Down
1 change: 0 additions & 1 deletion src/components/DynamicTabs.res
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ module TabInfo = {
}
}

external syntheticEventAsStr: ReactEvent.Form.t => string = "%identity"
module IndicationArrow = {
@react.component
let make = (~iconName, ~side, ~refElement: React.ref<Js.nullable<Dom.element>>, ~isVisible) => {
Expand Down
5 changes: 2 additions & 3 deletions src/components/MultiLineInputBox.res
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
external toReactFormEvent: 'a => ReactEvent.Form.t = "%identity"
@react.component
let make = (
~input: ReactFinalForm.fieldRenderPropsInput,
Expand All @@ -24,7 +23,7 @@ let make = (
}

let handleRemove = _ => {
input.onChange(""->toReactFormEvent)
input.onChange(""->Identity.stringToFormReactEvent)
setError(_ => None)
setFocus(_ => false)
handleRemove()
Expand All @@ -51,7 +50,7 @@ let make = (

if value === "" || error->Belt.Option.isNone {
setFocus(_ => false)
input.onChange(value->toReactFormEvent)
input.onChange(value->Identity.stringToFormReactEvent)
setShow(_ => false)
} else {
setError(_ => error)
Expand Down
13 changes: 6 additions & 7 deletions src/components/MultipleFileUpload.res
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
external toReactEvent: 'a => ReactEvent.Form.t = "%identity"
external arrToReactEvent: array<string> => ReactEvent.Form.t = "%identity"
external strToReactEvent: string => ReactEvent.Form.t = "%identity"
type dataTransfer
Expand Down Expand Up @@ -48,8 +47,8 @@ let make = (
let showToast = ToastState.useShowToast()

React.useEffect2(() => {
fileNamesInput.onChange(fileNames->toReactEvent)
fileTypeInput.onChange(fileTypes->toReactEvent)
fileNamesInput.onChange(fileNames->Identity.anyTypeToReactEvent)
fileTypeInput.onChange(fileTypes->Identity.anyTypeToReactEvent)
None
}, (fileNames, fileTypes))

Expand All @@ -61,7 +60,7 @@ let make = (
->getArrayFromJson([])
->Js.Array2.filteri((_, i) => indx != i)
->Js.Json.array
->toReactEvent,
->Identity.anyTypeToReactEvent,
)
setKey(prev => prev + 1)
}
Expand Down Expand Up @@ -130,7 +129,7 @@ let make = (
}

if !isCorrectFileFormat {
input.onChange(toReactEvent(""))
input.onChange(Identity.stringToFormReactEvent(""))
toast("Invalid file format", ToastError)
} else if isValid {
switch sizeLimit {
Expand Down Expand Up @@ -180,7 +179,7 @@ let make = (
} else {
break := true
}
input.onChange(toReactEvent(files))
input.onChange(Identity.anyTypeToReactEvent(files))
}
}

Expand Down Expand Up @@ -226,7 +225,7 @@ let make = (
setFilenames(prev => prev->Js.Array2.concat(filename))
setFileTypes(prev => prev->Js.Array2.concat(mimeType))
input.onChange(
toReactEvent(
Identity.anyTypeToReactEvent(
input.value->getArrayFromJson([])->Js.Array2.concat([file->Js.Json.string]),
),
)
Expand Down
5 changes: 2 additions & 3 deletions src/components/NestedDropdown.res
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ type rec options = {
value: string,
options?: array<options>,
}
external formToArray: 'a => ReactEvent.Form.t = "%identity"

module RenderOption = {
@react.component
Expand Down Expand Up @@ -38,7 +37,7 @@ module RenderOption = {
}
setSelectedData(_ => data)
setSelectedDataVal(_ => dataN)
input.onChange(data->formToArray)
input.onChange(data->Identity.anyTypeToReactEvent)
}
if selectedInd != index {
setSelectedInd(_ => index)
Expand Down Expand Up @@ -134,7 +133,7 @@ module RenderOptionList = {
| None => false
}
let onClick = _ => {
input.onChange(selectedData->formToArray)
input.onChange(selectedData->Identity.anyTypeToReactEvent)
}
<>
<div
Expand Down
1 change: 0 additions & 1 deletion src/components/NewDateRangePicker.res
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
open DateTimeUtils
external strToForm: string => ReactEvent.Form.t = "%identity"
external formEvAsString: ReactEvent.Form.t => string = "%identity"

let defaultCellHighlighter = (_): NewCalendar.highlighter => {
{
Expand Down
4 changes: 1 addition & 3 deletions src/components/Paginator.res
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
external formEventToStr: ReactEvent.Form.t => string = "%identity"

@react.component
let make = (
~totalResults,
Expand Down Expand Up @@ -50,7 +48,7 @@ let make = (
onBlur: _ev => (),
onChange: ev => {
setResultsPerPage(_ => {
ev->formEventToStr->Belt.Int.fromString->Belt.Option.getWithDefault(15)
ev->Identity.formReactEventToString->Belt.Int.fromString->Belt.Option.getWithDefault(15)
})
},
onFocus: _ev => (),
Expand Down
Loading

0 comments on commit 6a51261

Please sign in to comment.