formik#isObject TypeScript Examples

The following examples show how to use formik#isObject. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: settings.tsx    From protect-scotland with Apache License 2.0 4 votes vote down vote up
loadSettingsAsync = async (
  t: TFunction,
  setState: React.Dispatch<React.SetStateAction<SettingsContextState>>
) => {
  const [
    user,
    onboarded,
    completedExposureOnboarding
  ] = await AsyncStorage.multiGet([
    'scot.user',
    'scot.onboarded',
    'scot.completedExposureOnboarding'
  ]);

  const {data: res} = await requestWithCache('scot.settings', api.loadSettings);
  const apiSettings = res ?? {};

  const tc: TraceConfiguration = {
    ...defaultValue.traceConfiguration
  };
  if (apiSettings.exposureCheckInterval) {
    tc.exposureCheckInterval = Number(apiSettings.exposureCheckInterval);
  }
  if (apiSettings.storeExposuresFor) {
    tc.storeExposuresFor = Number(apiSettings.storeExposuresFor);
  }

  const getDbText = (settings: any, key: string): string => {
    let data =
      get(settings, `${key}.${i18n.language}`) ||
      get(settings, `${key}.en`) ||
      '';

    if (isObject(data)) {
      data = Object.keys(data).map((item: string) => {
        return data[item]
          .replace(/\\n/g, '\n')
          .replace(/(^|[^\n])\n(?!\n)/g, '$1\n\n');
      });
      return data;
    } else {
      return data.replace(/\\n/g, '\n').replace(/(^|[^\n])\n(?!\n)/g, '$1\n\n');
    }
  };

  const exposedTodo =
    getDbText(apiSettings, 'exposedTodoList') || t('closeContact:todo:list');

  const dpinText =
    getDbText(apiSettings, 'dpinText') || t('dataProtectionPolicy:text');

  const tandcText =
    getDbText(apiSettings, 'tandcText') || t('tandcPolicy:text');

  const solutionText =
    getDbText(apiSettings, 'solutionText') || t('config:solutionText');

  const testingInstructions =
    getDbText(apiSettings, 'testingInstructions') ||
    t('config:testingInstructions');

  const copy = {
    testResult: {
      text1:
        getDbText(apiSettings, 'copy.testResult.text1') ||
        t('tests:result:advice') + t('tests:result:text1'),
      text2:
        getDbText(apiSettings, 'copy.testResult.text2') ||
        t('tests:result:advice') + t('tests:result:text2')
    }
  };

  setState({
    loaded: true,
    user: user[1],
    onboarded: Boolean(onboarded[1]),
    completedExposureOnboarding: Boolean(completedExposureOnboarding[1]),
    latestVersion: apiSettings.latestVersion,
    traceConfiguration: tc,
    exposedTodo,
    copy,
    dpinText,
    tandcText,
    solutionText,
    testingInstructions,
    contactTracingNumber:
      apiSettings.contactTracingNumber || defaultContactTracingNumber,
    helplineNumber: apiSettings.helplineNumber || defaultHelplineNumber,
    ageLimit: apiSettings.ageLimit
      ? Number(apiSettings.ageLimit)
      : defaultValue.ageLimit,
    isolationEnd: apiSettings.isolationEnd
      ? Number(apiSettings.isolationEnd)
      : defaultValue.isolationEnd,
    testIsolationDuration: apiSettings.testIsolationDuration
      ? Number(apiSettings.isolationDuration)
      : defaultTestIsolationDuration,
    isolationDuration: apiSettings.isolationDuration
      ? Number(apiSettings.isolationDuration)
      : defaultIsolationDuration,
    isolationCompleteDuration: apiSettings.isolationCompleteDuration
      ? Number(apiSettings.isolationCompleteDuration)
      : isolationCompleteDuration,
    isolationParagraph: apiSettings.isolationParagraph
      ? i18n.t(apiSettings.isolationParagraph, {
          duration:
            apiSettings.testIsolationDuration || defaultTestIsolationDuration
        })
      : defaultIsolationParagraph,
    showCertUnderage: apiSettings.showCertUnderage
      ? apiSettings.showCertUnderage === 'true'
      : defaultShowCertUnderage,
    noticesWebPageURL: apiSettings.noticesWebPageURL
  });
}