Skip to content

Commit

Permalink
Merge pull request #3573 from webkom/ivarnakken/aba-234-give-user-war…
Browse files Browse the repository at this point in the history
  • Loading branch information
ivarnakken committed Feb 17, 2023
2 parents 460f9b2 + e3499bc commit ca21aa0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
12 changes: 11 additions & 1 deletion app/routes/users/components/UserSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ import type { UserEntity } from 'app/reducers/users';
import DeleteUser from 'app/routes/users/components/DeleteUser';
import RemovePicture from 'app/routes/users/components/RemovePicture';
import { spySubmittable } from 'app/utils/formSpyUtils';
import { createValidator, required, isEmail } from 'app/utils/validation';
import {
createValidator,
required,
isEmail,
isValidAllergy,
} from 'app/utils/validation';
import ChangePassword from './ChangePassword';
import UserImage from './UserImage';
import styles from './UserSettings.css';
Expand Down Expand Up @@ -52,6 +57,7 @@ const validate = createValidator({
lastName: [required()],
gender: [required()],
email: [required(), isEmail()],
allergies: [isValidAllergy()],
});

const UserSettings = (props: Props) => {
Expand All @@ -67,7 +73,9 @@ const UserSettings = (props: Props) => {
updateUser,
} = props;
const showAbakusMembership = user.isStudent;

const onSubmit = (values: FormValues) => updateUser(values);

return (
<div>
<div className={styles.pictureSection}>
Expand Down Expand Up @@ -130,8 +138,10 @@ const UserSettings = (props: Props) => {
component={RadioButton.Field}
/>
</RadioButtonGroup>

<Field
label="Matallergier/preferanser"
parse={(value) => value}
name="allergies"
component={TextInput.Field}
/>
Expand Down
10 changes: 10 additions & 0 deletions app/utils/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ export const timeIsAfter = (otherField, message) => (value, context) => {
return [true];
};

export const isValidAllergy =
(
message = 'La feltet stå tomt hvis du ikke har noen allergier/preferanser'
) =>
(value: string) => {
const notValidAnswers = ['ingen', 'ingenting', 'nei', 'nope', 'nada'];

return [!notValidAnswers.includes(value.toLowerCase()), message];
};

export const ifField = (field, validator) => (value, context) =>
context[field] ? validator(value, context) : [true];

Expand Down

0 comments on commit ca21aa0

Please sign in to comment.