Skip to content

Commit

Permalink
fix: form display bad request langAlt and comment
Browse files Browse the repository at this point in the history
  • Loading branch information
fufeck committed Jan 6, 2025
1 parent f28a8f2 commit d087982
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion components/bal/toponyme-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ function ToponymeEditor({

<LanguesRegionalesForm
initialValue={initialValue?.nomAlt}
validationMessage={getValidationMessage("lang_alt")}
validationMessage={getValidationMessage("langAlt")}
handleLanguages={setNomAlt}
/>
</FormInput>
Expand Down
9 changes: 6 additions & 3 deletions components/bal/voie-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ function VoieEditor({
trace: data ? data.geometry : null,
comment: comment ? comment : null,
};

// Add or edit a voie
const submit = initialValue
? toaster(
Expand Down Expand Up @@ -204,12 +203,16 @@ function VoieEditor({

<LanguesRegionalesForm
initialValue={initialValue?.nomAlt}
validationMessage={getValidationMessage("lang_alt")}
validationMessage={getValidationMessage("langAlt")}
handleLanguages={setNomAlt}
/>
</FormInput>

<Comment input={comment} onChange={onCommentChange} />
<Comment
input={comment}
onChange={onCommentChange}
validationMessage={getValidationMessage("comment")}
/>

{isMetric && <DrawEditor />}
</Pane>
Expand Down
8 changes: 6 additions & 2 deletions components/comment.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { Textarea, Label } from "evergreen-ui";
import { Label, Text, TextareaField } from "evergreen-ui";

import FormInput from "@/components/form-input";

interface CommentProps {
onChange: (e: React.ChangeEvent<HTMLTextAreaElement>) => void;
validationMessage?: string;
input?: string;
limit?: number;
isDisabled?: boolean;
}

function Comment({
onChange,
validationMessage = null,
input = "",
limit = 5000,
isDisabled = false,
Expand All @@ -20,11 +22,13 @@ function Comment({
<Label marginBottom={4} display="block">
Commentaire
</Label>
<Textarea
<TextareaField
placeholder="Cette note est confidentielle et ne sera pas diffusée."
value={input}
disabled={isDisabled}
onChange={input.length < limit ? onChange : () => {}}
isInvalid={Boolean(validationMessage)}
validationMessage={validationMessage}
/>
</FormInput>
);
Expand Down
8 changes: 1 addition & 7 deletions components/langues-regionales-form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ function LanguesRegionalesForm({
}: LanguesRegionalesFormProps) {
const [nomAlt, setNomAlt] = useState(objectToArray(initialValue));

const getAltValidationMessage = useCallback(() => {
if (validationMessage) {
return validationMessage.split(" : ")[1]; // Return message without code ISO as prefix
}
}, [validationMessage]);

const onAddForm = () => {
setNomAlt((prev) => [...prev, { code: null, value: "", id: uniqueId() }]);
};
Expand Down Expand Up @@ -83,7 +77,7 @@ function LanguesRegionalesForm({
availableLanguages={languesRegionales.filter(
({ code }) => !nomAlt.map(({ code }) => code).includes(code)
)}
validationMessage={getAltValidationMessage()}
validationMessage={validationMessage}
onChange={(value) => onLanguageChange(value, language.id)}
onDelete={() => onRemoveLanguage(language.id)}
/>
Expand Down

0 comments on commit d087982

Please sign in to comment.