Skip to content

Commit

Permalink
feat: add component for maintenance contractors
Browse files Browse the repository at this point in the history
  • Loading branch information
tensor5 committed Apr 24, 2024
1 parent 39da076 commit 5f71fdd
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/app/components/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import EditorDate from "./EditorDate";
import YAML from "yaml";
import { Col, Container, Row } from "design-react-kit";
import EditorContacts from "./EditorContacts";
import EditorContractors from "./EditorContractors";

const resolver: Resolver<PublicCode> = async (values) => {
const res = await validator(JSON.stringify(values), "main");
Expand Down Expand Up @@ -203,6 +204,7 @@ export default function Editor() {
required
/>
<EditorContacts />
<EditorContractors />
</Col>
</Row>
<hr />
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/EditorContacts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default function EditorContacts(): JSX.Element {
<tr>
<th className="align-top">#</th>
<th className="align-top">
{t(`publiccodeyml.${fieldName}.name.label`)}
{t(`publiccodeyml.${fieldName}.name.label`)} *
</th>
<th className="align-top">
{t(`publiccodeyml.${fieldName}.email.label`)}
Expand Down
100 changes: 100 additions & 0 deletions src/app/components/EditorContractors.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import { Button, Icon, Input, Table } from "design-react-kit";
import { get } from "lodash";
import { useController, useFieldArray, useFormContext } from "react-hook-form";
import { useTranslation } from "react-i18next";

import PublicCode from "../contents/publiccode";

const fieldName = "maintenance.contractors";
const subfields = ["name", "until", "email", "website"] as const;

export default function EditorContractors(): JSX.Element {
const { control, register } = useFormContext<PublicCode, typeof fieldName>();
const { append, fields, remove } = useFieldArray<
PublicCode,
typeof fieldName
>({
control,
name: fieldName,
});
const {
field,
formState: { errors },
} = useController<PublicCode, typeof fieldName>({
control,
name: fieldName,
});
const { t } = useTranslation();

return (
<fieldset>
<legend>{t(`publiccodeyml.${fieldName}.label`)}</legend>
{field.value?.length === 0 ? null : (
<Table responsive>
<thead>
<tr>
<th className="align-top">#</th>
<th className="align-top">
{t(`publiccodeyml.${fieldName}.name.label`)} *
</th>
<th className="align-top">
{t(`publiccodeyml.${fieldName}.until.label`)} *
</th>
<th className="align-top">
{t(`publiccodeyml.${fieldName}.email.label`)}
</th>
<th>{t(`publiccodeyml.${fieldName}.website.label`)}</th>
<th></th>
</tr>
</thead>
<tbody>
{fields.map(({ id }, index) => (
<tr key={id}>
<th scope="row">{index + 1}</th>
{subfields.map((subfield) => {
const { ref, ...reg } = register(
`${fieldName}.${index}.${subfield}`
);

return (
<td key={subfield}>
<Input
{...reg}
innerRef={ref}
type={subfield === "until" ? "date" : "text"}
valid={
get(errors, `${fieldName}.${index}.${subfield}`) &&
false
}
validationText={get(
errors,
`${fieldName}.${index}.${subfield}.message`
)}
/>
</td>
);
})}
<td>
<Button
color="link"
icon
onClick={() => remove(index)}
size="xs"
>
<Icon icon="it-delete" size="sm" title="Remove feature" />
</Button>
</td>
</tr>
))}
</tbody>
</Table>
)}
<Button
color="primary"
onClick={() => append({ name: "", until: "", email: "", website: "" })}
>
{t("editor.form.addnew")}
</Button>
</fieldset>
);
}
6 changes: 5 additions & 1 deletion src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,12 @@
"label": "Until",
"description": "The date the maintenance is going to end. In case of community maintenance, the value should not be more than 2 years in the future, and thus will need to be regularly updated as the community continues working on the project."
},
"email": {
"description": "The e-mail address of the technical contact. It must be an email address of where the technical contact can be directly reached; do NOT populate it with mailing-lists or generic contact points like info@acme.inc. ",
"label": "Email"
},
"website": {
"label": "website",
"label": "Website",
"description": "The maintainer website. It can either point to the main institutional website, or to a more project-specific page or website."
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/i18n/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,12 @@
"label": "Until",
"description": "The date the maintenance is going to end. In case of community maintenance, the value should not be more than 2 years in the future, and thus will need to be regularly updated as the community continues working on the project."
},
"email": {
"description": "The e-mail address of the technical contact. It must be an email address of where the technical contact can be directly reached; do NOT populate it with mailing-lists or generic contact points like info@acme.inc. ",
"label": "Email"
},
"website": {
"label": "website",
"label": "Website",
"description": "The maintainer website. It can either point to the main institutional website, or to a more project-specific page or website."
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/i18n/locales/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@
"label": "Email",
"description": "L’indirizzo email del contatto tecnico. Deve essere un indirizzo email per il contatto diretto con il tecnico; NON compilare questo campo con mailing-list o punti di contatto generico tipo “info@acme.inc”."
},
"email": {
"description": "L’indirizzo email del contatto tecnico. NON compilare questo campo con mailing-list o punti di contatto generico tipo “info@acme.inc”.",
"label": "Email"
},
"website": {
"label": "Website",
"description": "L’indirizzo del sito del maintainer. Può puntare al principale sito istituzionale, o ad una pagina o sito più specifica."
Expand Down

0 comments on commit 5f71fdd

Please sign in to comment.