Skip to content

Commit 49061cd

Browse files
authored
fix: Persist post code when opening privacy information (#347)
* Add intro values to store * Replace local state by store values * Remove comments
1 parent 1ca6ee2 commit 49061cd

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

src/components/WelcomeStepsModal/WelcomeModalPostalCode.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { makeStyles } from "@material-ui/core/styles";
88
import { switchViewToPlace } from "src/state/thunks/handleSearchQuery";
99
import { Link, useHistory } from "react-router-dom";
1010
import { WelcomeModalStep } from "./welcomeStepsConfig";
11+
import { useSelector } from "react-redux";
12+
import { State } from "src/state";
1113

1214
function isValidPostalCode(text: string) {
1315
return /^[0-9]{5}$/.test(text);
@@ -33,10 +35,10 @@ export const WelcomeModalPostalCode: React.FC = () => {
3335
const classes = { ...useCommonWelcomeModalStyles(), ...useStyles() };
3436
const dispatch = useThunkDispatch();
3537
const history = useHistory();
36-
const [postCode, setPostCode] = useState("");
38+
const postCode = useSelector((state: State) => state.app.intro.postCode);
39+
const checked = useSelector((state: State) => state.app.intro.isPrivacyChecked);
3740
const [validatePostalCode, setValidatePostalCode] = useState(false);
3841
const [validateCheckbox, setValidateCheckbox] = useState(false);
39-
const [checked, setChecked] = useState(false);
4042

4143
function onSkip() {
4244
setValidateCheckbox(true);
@@ -64,7 +66,7 @@ export const WelcomeModalPostalCode: React.FC = () => {
6466
}
6567

6668
function handleCheckedChange(event: React.ChangeEvent<HTMLInputElement>) {
67-
setChecked(event.target.checked);
69+
dispatch(AppApi.setIntroValues({ isPrivacyChecked: event.target.checked }));
6870
}
6971

7072
const isCheckboxError = validateCheckbox && !checked;
@@ -83,15 +85,16 @@ export const WelcomeModalPostalCode: React.FC = () => {
8385
helperText={isPostCodeError ? "Bitte valide PLZ eingeben" : null}
8486
variant="outlined"
8587
type="number"
88+
value={postCode}
8689
onChange={(event) => {
87-
setPostCode(event.target.value);
90+
dispatch(AppApi.setIntroValues({ postCode: event.target.value }));
8891
}}
8992
onKeyPress={onKeyPress}
9093
style={{ margin: "50px 0 30px 0", width: "180px", height: "80px" }}
9194
/>
9295

9396
<div style={{ display: "flex", flexDirection: "row", alignItems: "center", marginBottom: "10px" }}>
94-
<Checkbox value={checked} onChange={handleCheckedChange} />
97+
<Checkbox value={checked} checked={checked} onChange={handleCheckedChange} />
9598
<Typography className={classes.smallText} style={isCheckboxError ? { color: "red" } : {}}>
9699
Ja, ich habe die <Link to={WelcomeModalStep.StepPostalCodeDataPrivacy}>Datenschutzerklärung</Link> zur
97100
Kenntnis genommen und willige ein.

src/state/app.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ export type FeaturePropId = {
6262

6363
export type MapSetHolder = Record<VisualId, Record<string, MapSet>>;
6464

65+
export type Intro = {
66+
postCode: string;
67+
isPrivacyChecked: boolean;
68+
};
69+
6570
export interface AppState {
6671
viewport: Viewport;
6772
currentPosition: Array<number> | null;
@@ -87,6 +92,7 @@ export interface AppState {
8792
currentLayerGroup: LayerGroup;
8893
infoDialogs: Record<string, boolean>;
8994
userPostalCode: number | null;
95+
intro: Intro;
9096
}
9197

9298
export const defaultAppState: AppState = {
@@ -122,6 +128,10 @@ export const defaultAppState: AppState = {
122128
currentLayerGroup: defaultLayerGroup,
123129
infoDialogs: {},
124130
userPostalCode: null,
131+
intro: {
132+
postCode: "",
133+
isPrivacyChecked: false,
134+
},
125135
};
126136

127137
class AppReducer extends Reducer<AppState> {
@@ -228,6 +238,9 @@ class AppReducer extends Reducer<AppState> {
228238
public setUserPostalCode(postalCode: number) {
229239
this.state.userPostalCode = postalCode;
230240
}
241+
public setIntroValues(values: Partial<Intro>) {
242+
this.state.intro = { ...this.state.intro, ...values };
243+
}
231244
}
232245

233246
const AppReducerInstance = new AppReducer();

0 commit comments

Comments
 (0)