How to use the formik.withFormik 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 sysgears / apollo-universal-starter-kit / packages / client / src / modules / contact / components / ContactForm.native.jsx View on Github external
display: 'flex',
    justifyContent: 'center',
    padding: 15
  },
  modalText: {
    textAlign: 'center',
    paddingBottom: 15
  },
  formView: {
    flex: 1,
    alignSelf: 'stretch'
  },
  submit
});

const ContactFormWithFormik = withFormik({
  mapPropsToValues: () => ({ content: '', email: '', name: '' }),
  async handleSubmit(
    values,
    {
      resetForm,
      setErrors,
      setStatus,
      props: { onSubmit }
    }
  ) {
    Keyboard.dismiss();

    try {
      await onSubmit(values);
      resetForm();
    } catch (e) {
github GenesisVision / web-client / packages / shared / modules / wallet-withdraw / components / wallet-withdraw-form.tsx View on Github external
interface Props extends WithTranslation, OwnProps {}

interface OwnProps {
  twoFactorEnabled: boolean;
  wallets: WalletData[];
  currentWallet: WalletData;
  onSubmit(
    data: IWalletWithdrawFormValues,
    setSubmitting: SetSubmittingType
  ): void;
  errorMessage?: string;
}

const WalletWithdrawForm = compose>(
  translate(),
  withFormik({
    displayName: "wallet-withdraw",
    mapPropsToValues: ({ currentWallet: { id, currency } }) => ({
      [FIELDS.id]: id,
      [FIELDS.currency]: currency,
      [FIELDS.amount]: "",
      [FIELDS.address]: "",
      [FIELDS.twoFactorCode]: ""
    }),
    validationSchema: ({ t, twoFactorEnabled }: Props) =>
      lazy(
        (values: IWalletWithdrawFormValues): Schema => {
          switch (values[FIELDS.currency]) {
            case "GVT":
            case "ETH":
            case "USDT":
              return object().shape({
github GenesisVision / web-client / packages / shared / modules / fund-notifications / fund-notification-create-form.js View on Github external
<div>
            
              {t("buttons.create")}
            
          </div>
        
      
    );
  }
}

FundNotificationCreateForm.propTypes = {};

export default compose(
  translate(),
  withFormik({
    displayName: "create-notification",
    mapPropsToValues: () =&gt; ({
      type: "FundCondition",
      conditionType: "Profit",
      conditionAmount: ""
    }),
    validationSchema: ({ t }) =&gt;
      object().shape({
        conditionAmount: number().required(
          t("notifications-page.create.amount-required")
        )
      }),
    handleSubmit: (values, { props }) =&gt; props.onSubmit(values)
  })
)(FundNotificationCreateForm);
github sysgears / apollo-universal-starter-kit / modules / contact / client-react / components / ContactForm.tsx View on Github external
name="content"
      component={RenderField}
      type="textarea"
      label={t('form.field.content')}
      value={values.content}
    /&gt;
    <div>
      {errors &amp;&amp; errors.errorMsg &amp;&amp; {errors.errorMsg}}
      <button type="submit" color="primary">
        {t('form.btnSubmit')}
      </button>
    </div>
  
);

const ContactFormWithFormik = withFormik({
  enableReinitialize: true,
  mapPropsToValues: () =&gt; ({ content: '', email: '', name: '' }),
  async handleSubmit(values, { resetForm, setErrors, setStatus, props: { onSubmit } }) {
    try {
      await onSubmit(values);
      resetForm();
      setStatus({ sent: true });
    } catch (e) {
      if (isFormError(e)) {
        setErrors(e.errors);
      } else {
        throw e;
      }
      setStatus({ sent: false });
    }
  },
github GenesisVision / web-client / packages / social-trader / src / modules / wallet-add-funds / components / wallet-add-funds-form.tsx View on Github external
);
};

const WalletAddFundsForm = compose&gt;(
  withLoader,
  withFormik({
    displayName: "wallet-deposit",
    mapPropsToValues: ({ currentWallet: { id } }) =&gt; ({
      [FIELDS.id]: id
    }),
    handleSubmit: () =&gt; {}
  }),
  React.memo
)(_WalletAddFundsForm);
export default WalletAddFundsForm;

enum FIELDS {
  id = "id"
}

interface FormValues {
  [FIELDS.id]: string;
github GenesisVision / web-client / packages / shared / components / program-withdraw / program-withdraw-amount-form.tsx View on Github external
id="programWithdrawAmountFormSubmit"
          className="invest-form__submit-button"
          disabled={
            (!values[FIELDS.amount] || !isValid) &amp;&amp; !values[FIELDS.withdrawAll]
          }
        &gt;
          {t("withdraw-program.next")}
        
      
    
  );
};

const ProgramWithdrawAmountForm = compose&gt;(
  translate(),
  withFormik({
    displayName: "withdraw-form",
    isInitialValid: true,
    mapPropsToValues: ({ formValues: { amount, withdrawAll } }) =&gt; ({
      [FIELDS.amount]: amount,
      [FIELDS.withdrawAll]: withdrawAll
    }),
    validationSchema: ({ t, availableToWithdraw }: Props) =&gt;
      object().shape({
        [FIELDS.withdrawAll]: boolean(),
        [FIELDS.amount]: mixed().when(FIELDS.withdrawAll, {
          is: false,
          then: number()
            .moreThan(0, t("withdraw-program.validation.amount-is-zero"))
            .max(
              availableToWithdraw,
              t("withdraw-program.validation.amount-more-than-available")
github GenesisVision / web-client / packages / manager / src / pages / programs / programs-settings / stop-out-level.tsx View on Github external
interface Props
  extends OwnProps,
    WithTranslation,
    FormikProps {}

interface OwnProps {
  stopOutLevel: number;
  onSubmit: (
    values: StopOutLevelFormValues,
    setSubmitting: SetSubmittingType
  ) =&gt; void;
}

const StopOutLevel = compose&gt;(
  translate(),
  withFormik({
    enableReinitialize: true,
    displayName: "edit-form",
    mapPropsToValues: ({ stopOutLevel }) =&gt; ({
      [FIELDS.stopOutLevel]: stopOutLevel || 100
    }),
    validationSchema: ({ t, stopOutLevel }: Props) =&gt;
      object().shape({
        [FIELDS.stopOutLevel]: number()
          .min(
            10,
            t(
              "manager.create-program-page.settings.validation.stop-out-less-ten"
            )
          )
          .max(
            stopOutLevel || 100,
github GenesisVision / web-client / packages / social-trader / src / pages / programs / programs-settings / change-broker / change-broker-form.tsx View on Github external
}

export interface ChangeBrokerFormValues {
  [FIELDS.brokerAccountTypeId]: string;
  [FIELDS.leverage]: number;
  [FIELDS.brokerFrom]: Broker;
}

const ChangeBrokerForm = compose&lt;
  React.ComponentType&lt;
    ChangeBrokerFormOwnProps &amp; WithBlurLoaderProps
  &gt;
&gt;(
  withBlurLoader,
  translate(),
  withFormik({
    enableReinitialize: true,
    displayName: "edit-form",
    mapPropsToValues: ({
      data: { brokers, currentAccountTypeId },
      currentLeverage
    }) =&gt; ({
      [FIELDS.brokerFrom]: safeGetElemFromArray(
        brokers,
        broker =&gt;
          !!broker.accountTypes.find(
            accountType =&gt; accountType.id === currentAccountTypeId
          )
      ),
      [FIELDS.brokerAccountTypeId]: currentAccountTypeId,
      [FIELDS.leverage]: currentLeverage
    }),
github GenesisVision / web-client / packages / manager / src / pages / create-program / components / create-program-settings / create-program-settings.tsx View on Github external
walletCurrency={wallet.currency}
          /&gt;
          
        
      
    );
  }
}

const CreateProgramSettings = compose&gt;(
  translate(),
  withFormik({
    displayName: "CreateProgramSettingsForm",
    mapPropsToValues: ({
      wallet,
      broker,
      programCurrency,
      leverage,
      programsInfo,
      accountType
    }) =&gt; {
      const periodLength =
        programsInfo.periods.length === 1 ? programsInfo.periods[0] : undefined;
      return {
        [CREATE_PROGRAM_FIELDS.tradesDelay]: "None",
        [CREATE_PROGRAM_FIELDS.stopOutLevel]: 100,
        [CREATE_PROGRAM_FIELDS.brokerAccountTypeId]: accountType
          ? accountType.id