Skip to content

Commit da5b89c

Browse files
committed
fix(Wrong validation for email in contact #448): fixed email validation error
1 parent b9b9466 commit da5b89c

4 files changed

Lines changed: 14 additions & 4 deletions

File tree

go.work.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73r
2222
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
2323
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
2424
golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
25+
golang.org/x/sync v0.12.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
2526
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
2627
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
2728
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
2829
golang.org/x/term v0.29.0/go.mod h1:6bl4lRlvVuDgSf3179VpIxBF0o10JUpXWOnI7nErv7s=
30+
golang.org/x/term v0.30.0/go.mod h1:NYYFdzHoI5wRh/h5tDMdMqCqPJZEuNqVR5xJLd/n67g=
2931
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
3032
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
3133
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=

src/app/components/EditorContacts.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ import { get } from "lodash";
99
import { useController, useFieldArray, useFormContext } from "react-hook-form";
1010
import { useTranslation } from "react-i18next";
1111

12-
import PublicCode from "../contents/publiccode";
1312
import { useRef } from "react";
13+
import PublicCode from "../contents/publiccode";
1414

1515
const fieldName = "maintenance.contacts";
1616
const subfields = ["name", "email", "phone", "affiliation"] as const;
17+
const setValueAsUndefinedFields = new Set(["email", "phone", "affiliation"]);
1718

1819
export default function EditorContacts(): JSX.Element {
1920
const { control, register } = useFormContext<PublicCode, typeof fieldName>();
@@ -80,7 +81,10 @@ export default function EditorContacts(): JSX.Element {
8081
<th scope="row">{index + 1}</th>
8182
{subfields.map((subfield) => {
8283
const { ref, ...reg } = register(
83-
`${fieldName}.${index}.${subfield}`
84+
`${fieldName}.${index}.${subfield}`,
85+
{
86+
setValueAs: value => setValueAsUndefinedFields.has(subfield) && value === "" ? undefined : value
87+
}
8488
);
8589

8690
return (

src/app/components/EditorContractors.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import PublicCode from "../contents/publiccode";
77

88
const fieldName = "maintenance.contractors";
99
const subfields = ["name", "until", "email", "website"] as const;
10+
const setValueAsUndefinedFields = new Set(["email", "website"]);
1011

1112
export default function EditorContractors(): JSX.Element {
1213
const { control, register } = useFormContext<PublicCode, typeof fieldName>();
@@ -60,7 +61,10 @@ export default function EditorContractors(): JSX.Element {
6061
<th scope="row">{index + 1}</th>
6162
{subfields.map((subfield) => {
6263
const { ref, ...reg } = register(
63-
`${fieldName}.${index}.${subfield}`
64+
`${fieldName}.${index}.${subfield}`,
65+
{
66+
setValueAs: (value: string | Date) => setValueAsUndefinedFields.has(subfield) && value === "" ? undefined : value
67+
}
6468
);
6569

6670
return (

src/generated/licenses.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)