From 08fd8da60532e8552813de9f81b2fe6d21b376a8 Mon Sep 17 00:00:00 2001 From: Steve Rydz Date: Fri, 2 Feb 2024 10:59:55 +0000 Subject: [PATCH] Make inputs for websites on listing page URL (#4520) * Make inputs for websites on listing page URL * Fix URL validation on listing page --- .../publisher/listing/components/App/App.tsx | 22 +++++------ .../MultipleInputs/MultipleInputs.tsx | 37 +++++++++++++++---- .../listing/components/UrlInput/UrlInput.tsx | 35 ++++++++++++++++++ .../listing/components/UrlInput/index.ts | 1 + .../ContactInformationSection.tsx | 11 +++++- .../js/publisher/listing/utils/getChanges.ts | 16 +++++--- 6 files changed, 97 insertions(+), 25 deletions(-) create mode 100644 static/js/publisher/listing/components/UrlInput/UrlInput.tsx create mode 100644 static/js/publisher/listing/components/UrlInput/index.ts diff --git a/static/js/publisher/listing/components/App/App.tsx b/static/js/publisher/listing/components/App/App.tsx index cc5a7b06a3..ba84b753fd 100644 --- a/static/js/publisher/listing/components/App/App.tsx +++ b/static/js/publisher/listing/components/App/App.tsx @@ -1,10 +1,6 @@ import { useState, useEffect } from "react"; import { useForm } from "react-hook-form"; -import { - Form, - Strip, - Notification -} from "@canonical/react-components"; +import { Form, Strip, Notification } from "@canonical/react-components"; import { getChanges, @@ -34,10 +30,11 @@ function App() { const [isSaving, setIsSaving] = useState(false); const [hasSaved, setHasSaved] = useState(false); - const [savedError, setSavedError] = useState(false); - const [showMetadataWarningModal, setShowMetadataWarningModal] = useState( - false - ); + const [savedError, setSavedError] = useState< + boolean | { code: string; message: string }[] + >(false); + const [showMetadataWarningModal, setShowMetadataWarningModal] = + useState(false); const [formData, setFormData] = useState({}); const [updateMetadataOnRelease, setUpdateMetadataOnRelease] = useState( listingData?.update_metadata_on_release @@ -213,8 +210,11 @@ function App() { setSavedError(false); }} > - Changes have not been saved.
- {savedError === true ? "Something went wrong." : savedError.map((error) => `${error.message}`).join("\n")} + Changes have not been saved. +
+ {savedError === true + ? "Something went wrong." + : savedError.map((error) => `${error.message}`).join("\n")} )} diff --git a/static/js/publisher/listing/components/MultipleInputs/MultipleInputs.tsx b/static/js/publisher/listing/components/MultipleInputs/MultipleInputs.tsx index ff8fff040f..3a5c4e4a2c 100644 --- a/static/js/publisher/listing/components/MultipleInputs/MultipleInputs.tsx +++ b/static/js/publisher/listing/components/MultipleInputs/MultipleInputs.tsx @@ -2,19 +2,31 @@ import React from "react"; import { useFieldArray } from "react-hook-form"; import { Row, Col, Button, Icon } from "@canonical/react-components"; +import UrlInput from "../UrlInput"; + type Props = { fieldName: string; label: string; register: Function; control: any; + getFieldState: Function; }; -function MultipleInputs({ fieldName, label, register, control }: Props) { +function MultipleInputs({ + fieldName, + label, + register, + control, + getFieldState, +}: Props) { const { fields, append, remove } = useFieldArray({ control, name: fieldName, }); + const urlFieldNames = ["websites", "donations", "source-code", "issues"]; + const isUrl = urlFieldNames.includes(fieldName); + return ( @@ -24,14 +36,23 @@ function MultipleInputs({ fieldName, label, register, control }: Props) { {fields.map((field, index) => ( -
- -
+ ) : ( +
+ +
+ )}