feat(dashboard-v2): add skylink validation & parsing
This commit is contained in:
parent
614b7791ec
commit
9dd4b8eb17
|
@ -1,15 +1,22 @@
|
||||||
import * as Yup from "yup";
|
import * as Yup from "yup";
|
||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
import { Formik, Form } from "formik";
|
import { Formik, Form } from "formik";
|
||||||
|
import { parseSkylink } from "skynet-js";
|
||||||
import accountsService from "../../services/accountsService";
|
|
||||||
|
|
||||||
import { Button } from "../Button";
|
import { Button } from "../Button";
|
||||||
import { TextField } from "../Form/TextField";
|
import { TextField } from "../Form/TextField";
|
||||||
import { CircledProgressIcon, PlusIcon } from "../Icons";
|
import { CircledProgressIcon, PlusIcon } from "../Icons";
|
||||||
|
|
||||||
const newSkylinkSchema = Yup.object().shape({
|
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 }) => (
|
export const AddSkylinkToAPIKeyForm = ({ addSkylink }) => (
|
||||||
|
@ -19,7 +26,7 @@ export const AddSkylinkToAPIKeyForm = ({ addSkylink }) => (
|
||||||
}}
|
}}
|
||||||
validationSchema={newSkylinkSchema}
|
validationSchema={newSkylinkSchema}
|
||||||
onSubmit={async ({ skylink }, { resetForm }) => {
|
onSubmit={async ({ skylink }, { resetForm }) => {
|
||||||
if (await addSkylink(skylink)) {
|
if (await addSkylink(parseSkylink(skylink))) {
|
||||||
resetForm();
|
resetForm();
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
|
Reference in New Issue