How to use the formik.useFormik function in formik

To help you get started, we’ve selected a few formik examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Mines-Paristech-Students / Portail-des-eleves / frontend / src / pages / courses / forms / Edit.tsx View on Github external
const FetchQuestionsModal = ({ course }) => {
    const [isFetching, setIsFetching] = useState(true);
    const [isLoading, setIsLoading] = useState(true);
    const [forms, setForms] = useState([]);
    const newToast = useContext(ToastContext);

    const formik = useFormik({
        initialValues: { idForm: -1, questions: [] },
        validate: (values) => { return (values.questions.length == 0 ? { questions: "Empty" } : {}) },
        onSubmit: (values, { setSubmitting }) => {
            Promise.all(values.questions.map((question: Question) => {
                question.id = undefined;
                question.form = course.form;
                console.log(question.id);
                return (
                    api.courses.forms.questions
                        .save(question)
                        .then((question) => {
                            newToast({
                                message: `Could not insert question ${question.label}`,
                                level: ToastLevel.Success,
                            });
                        })
github centreon / centreon / www / front_src / src / Resources / Filter / Save / CreateFilterDialog.tsx View on Github external
const CreateFilterDialog = ({
  filter,
  onCreate,
  open,
  onCancel,
}: Props): JSX.Element => {
  const { toFilter, toRawFilter } = useAdapters();

  const { t } = useTranslation();

  const { sendRequest, sending } = useRequest({
    request: createFilter,
  });

  const form = useFormik({
    initialValues: {
      name: '',
    },
    validationSchema: Yup.object().shape({
      name: Yup.string().required(labelRequired),
    }),
    onSubmit: (values) => {
      sendRequest(
        omit(
          ['id'],
          toRawFilter({
            id: '',
            name: values.name,
            criterias: filter.criterias,
          }),
        ),
github pipe-cd / pipe / pkg / app / web / src / components / edit-application-drawer / index.tsx View on Github external
function EditApplicationDrawer({ onUpdated }) {
    const dispatch = useAppDispatch();

    const app = useAppSelector((state) =>
      state.updateApplication.targetId
        ? selectAppById(state.applications, state.updateApplication.targetId)
        : undefined
    );

    const formik = useFormik({
      initialValues: app
        ? {
            name: app.name,
            env: app.envId,
            kind: app.kind,
            pipedId: app.pipedId,
            repoPath: app.gitPath?.path || "",
            repo: app.gitPath?.repo || { id: "", remote: "", branch: "" },
            configFilename: app.gitPath?.configFilename || "",
            cloudProvider: app.cloudProvider,
          }
        : emptyFormValues,
      validateOnMount: true,
      validationSchema,
      enableReinitialize: true,
      async onSubmit(values) {
github pipe-cd / pipe / pkg / app / web / src / components / application-detail / components / description.tsx View on Github external
function ApplicationDescription({ description, onUpdate }) {
    const [editing, setEditing] = useState(false);
    const classes = useStyles();
    const formik = useFormik({
      initialValues: { description },
      async onSubmit({ description }) {
        await onUpdate(description);
        setEditing(false);
      },
    });

    if (editing) {
      return (
        <form>
          </form>
github otofu-square / realworld-react-redux / src / views / pages / Signup / useForm.ts View on Github external
export const useForm = () =&gt; {
  const dispatch = useDispatch();
  const formik = useFormik({
    initialValues,
    onSubmit: async (values, formikHelper) =&gt; {
      const errorResponse = await dispatch(userOperations.create(values));
      if (!errorResponse) {
        dispatch(push("/"));
      } else {
        const formattedErrors = R.mapObjIndexed(
          R.join(", "),
          errorResponse.errors
        );
        formikHelper.setErrors(formattedErrors);
      }
    }
  });
  return formik;
};
github seashell / drago / ui / src / views / interfaces / details / index.js View on Github external
const InterfaceDetailsView = () => {
  const navigate = useNavigate()
  const location = useLocation()
  const urlParams = useParams()

  const { hostId } = location.state || {}

  if (hostId === undefined) {
    navigate(`/ui/hosts`)
  }

  const formik = useFormik({
    initialValues: {
      name: null,
      networkId: null,
      ipAddress: null,
      listenPort: null,
    },
    validationSchema: Yup.object().shape({
      name: Yup.string()
        .required()
        .nullable(),
      networkId: Yup.string().nullable(),
      ipAddress: Yup.string().nullable(),
      listenPort: Yup.number()
        .positive()
        .nullable(),
    }),
github seashell / drago / ui / src / views / networks / new / index.js View on Github external
const NewNetwork = () => {
  const navigate = useNavigate()
  const { success, error } = useToast()

  const formik = useFormik({
    initialValues: {
      name: '',
      addressRange: '',
    },
    validationSchema: Yup.object().shape({
      name: Yup.string().required().nullable(),
      addressRange: Yup.string().required().nullable(),
    }),
  })

  const [createNetwork, createNetworkMutation] = useMutation(CREATE_NETWORK, {
    variables: {},
    onCompleted: () => {
      success('Network created')
      navigate('/ui/networks/')
    },
github seashell / drago / ui / src / views / hosts / new / index.js View on Github external
const NewHostView = ({ networkId }) => {
  const navigate = useNavigate()

  const formik = useFormik({
    initialValues: {
      name: null,
      labels: [],
      advertiseAddress: null,
    },
    validationSchema: Yup.object().shape({
      name: Yup.string()
        .required()
        .nullable(),
      advertiseAddress: Yup.string().nullable(),
    }),
  })

  const [createHost, createHostMutation] = useMutation(CREATE_HOST, {
    variables: { networkId },
    onCompleted: () => {
github seashell / drago / ui / src / views / settings / tokens / index.js View on Github external
const TokensView = () => {
  const location = useLocation()

  const [token, setToken] = useState(undefined)
  const [tokenSecret, setTokenSecret] = useLocalStorage('drago.settings.acl.token', undefined)
  const [isAuthenticated, setAuthenticated] = useState(undefined)

  const formik = useFormik({
    initialValues: {
      secret: tokenSecret || '',
    },
    validationSchema: Yup.object().shape({
      secret: Yup.string(),
    }),
  })

  const handleGetSelfQueryCompleted = (data) => {
    if (data.result !== null) {
      setToken(data.result)
    }
  }

  const handleGetSelfQueryError = (errors) => {
    if (errors.networkError.statusCode === 404) {
github centreon / centreon / www / front_src / src / Resources / Actions / Resource / Downtime / index.tsx View on Github external
showMessage({ message, severity: Severity.success });

  const { locale, timezone, username } = useUserContext();

  const {
    sendRequest: sendSetDowntimeOnResources,
    sending: sendingSetDowntingOnResources,
  } = useRequest({
    request: setDowntimeOnResources,
  });

  const currentDate = new Date();
  const twoHoursMs = 2 * 60 * 60 * 1000;
  const twoHoursLaterDate = new Date(currentDate.getTime() + twoHoursMs);

  const form = useFormik({
    initialValues: {
      dateStart: currentDate,
      timeStart: currentDate,
      dateEnd: twoHoursLaterDate,
      timeEnd: twoHoursLaterDate,
      fixed: true,
      duration: {
        value: 3600,
        unit: 'seconds',
      },
      comment: '',
      downtimeAttachedResources: true,
    },
    onSubmit: (values, { setSubmitting }) => {
      setSubmitting(true);