Skip to content

Commit 4f770ee

Browse files
committed
WIP
1 parent 082e19a commit 4f770ee

File tree

3 files changed

+37
-16
lines changed

3 files changed

+37
-16
lines changed
Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,50 @@
1-
2-
3-
import { Field, Formik } from "formik";
41
// License: LGPL-3.0-or-later
5-
import * as React from "react";
2+
import React, {useCallback} from "react";
3+
import { Field, Formik } from "formik";
4+
65
import { Location } from "./types";
6+
import { LocalizedCountry, Subregion } from "../../../countries";
7+
import type {Schema as YupSchema} from 'yup';
8+
import useYup from '../../../hooks/'
9+
import { noop } from "lodash";
710

11+
type OnUpdateArgs = {location:Location, isValid:boolean}
12+
type ValidationSchemaArgs = {validCountries?:LocalizedCountry[], validStates?:Subregion[]}
813

914
interface LocationSelectorProps {
1015
enableReinitialize:boolean;
1116
initialLocation:Location;
12-
onUpdate:(location:Location) => void;
17+
onUpdate:(args:OnUpdateArgs) => void;
18+
validationSchema:(args:ValidationSchemaArgs) => YupSchema<{city:any, country:any, stateCode:any}, unknown>;
1319
}
1420

1521

16-
function LocationSelector(props:LocationSelectorProps) : JSX.Element {
1722

23+
function LocationSelector(props:LocationSelectorProps) : JSX.Element {
24+
const inputValidationSchema = props.validationSchema;
25+
const yup = useYup();
26+
27+
const setLatest
28+
29+
const validationSchema = useCallback(() => {
30+
if (inputValidationSchema === noop) {
31+
return () => yup.
32+
}
33+
else {
34+
return inputValidationSchema;
35+
}
36+
}, [inputValidationSchema])
1837

1938

20-
return <Formik onSubmit()>
39+
return <Formik validationSchema>
40+
2141
</Formik>;
2242
}
2343

2444
LocationSelector.defaultProps = {
2545
enableReinitalize: false,
26-
initialLocation: {country: "US", stateCode: "", city: ""}
46+
initialLocation: {country: "US", stateCode: "", city: ""},
47+
validationSchema: noop,
2748
}
2849

2950
export default LocationSelector;
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11

22
// License: LGPL-3.0-or-later
3-
import * as React from "react"
3+
import * as React, {Suspense} from "react";
44

55

6-
interface IStateCodeProps {
6+
interface StateCodeProps {
77
}
88

99

10-
function StateCode(props:IStateCodeProps) : JSX.Element {
11-
return (
12-
<React.Fragment>
13-
</React.Fragment>
14-
);
10+
function StateCode(props:StateCodeProps) : JSX.Element {
11+
12+
return <Suspense fallback={/* you */}>
13+
14+
</Suspense>;
15+
1516
}
1617

1718
export default StateCode

app/javascript/countries.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
// License: LGPL-3.0-or-later
32
import flatten from 'lodash/flatten';
43

0 commit comments

Comments
 (0)