From 9dd4b8eb172b1b2de99bdf20aa51689062b7e9bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Leszczyk?= Date: Fri, 25 Mar 2022 11:45:58 +0100 Subject: [PATCH] feat(dashboard-v2): add skylink validation & parsing --- .../components/forms/AddSkylinkToAPIKeyForm.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/dashboard-v2/src/components/forms/AddSkylinkToAPIKeyForm.js b/packages/dashboard-v2/src/components/forms/AddSkylinkToAPIKeyForm.js index 8c01a0fb..fd9fe54b 100644 --- a/packages/dashboard-v2/src/components/forms/AddSkylinkToAPIKeyForm.js +++ b/packages/dashboard-v2/src/components/forms/AddSkylinkToAPIKeyForm.js @@ -1,15 +1,22 @@ import * as Yup from "yup"; import PropTypes from "prop-types"; import { Formik, Form } from "formik"; - -import accountsService from "../../services/accountsService"; +import { parseSkylink } from "skynet-js"; import { Button } from "../Button"; import { TextField } from "../Form/TextField"; import { CircledProgressIcon, PlusIcon } from "../Icons"; const newSkylinkSchema = Yup.object().shape({ - skylink: Yup.string().required("Provide a valid Skylink"), // TODO: Comprehensive Skylink validation + skylink: Yup.string() + .required("Skylink is required") + .test("skylink", "Provide a valid Skylink", (value) => { + try { + return parseSkylink(value) !== null; + } catch { + return false; + } + }), }); export const AddSkylinkToAPIKeyForm = ({ addSkylink }) => ( @@ -19,7 +26,7 @@ export const AddSkylinkToAPIKeyForm = ({ addSkylink }) => ( }} validationSchema={newSkylinkSchema} onSubmit={async ({ skylink }, { resetForm }) => { - if (await addSkylink(skylink)) { + if (await addSkylink(parseSkylink(skylink))) { resetForm(); } }}