import * as Yup from "yup"; import { forwardRef, useImperativeHandle, useState } from "react"; import PropTypes from "prop-types"; import { Formik, Form, FieldArray } from "formik"; import { parseSkylink } from "skynet-js"; import cn from "classnames"; import accountsService from "../../services/accountsService"; import { Alert } from "../Alert"; import { Button } from "../Button"; import { CopyButton } from "../CopyButton"; import { TextField } from "../Form/TextField"; import { PlusIcon, TrashIcon } from "../Icons"; const skylinkValidator = (optional) => (value) => { if (!value) { return optional; } try { return parseSkylink(value) !== null; } catch { return false; } }; const newPublicAPIKeySchema = Yup.object().shape({ name: Yup.string(), skylinks: Yup.array().of(Yup.string().test("skylink", "Provide a valid Skylink", skylinkValidator(false))), nextSkylink: Yup.string().when("skylinks", { is: (skylinks) => skylinks.length === 0, then: (schema) => schema.test("skylink", "Provide a valid Skylink", skylinkValidator(true)), otherwise: (schema) => schema.test("skylink", "Provide a valid Skylink", skylinkValidator(true)), }), }); const State = { Pure: "PURE", Success: "SUCCESS", Failure: "FAILURE", }; export const AddPublicAPIKeyForm = forwardRef(({ onSuccess }, ref) => { const [state, setState] = useState(State.Pure); const [generatedKey, setGeneratedKey] = useState(null); useImperativeHandle(ref, () => ({ reset: () => setState(State.Pure), })); return (
Please copy your new API key below. We'll never show it again!
{generatedKey}