All files / src/components/ManualAddCompanyForm/FormButtons FormButtons.tsx

84.21% Statements 16/19
100% Branches 0/0
50% Functions 2/4
84.21% Lines 16/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 694x             4x   4x 4x 4x 4x 4x   10x 182x   180x 180x 180x 180x 180x   180x                                         1x                                              
import React from 'react';
import {
  Required,
  Modal,
  Button,
  useFormContext,
  useI18nContext,
} from '@procore/core-react';
import { ManualAddCompanyFormData } from '../schema';
import { useAddToProject } from '../../../hooks/useAddToProject';
import { useAddCompanyContext } from '../../../Context/AddCompanyContext';
import { Loader } from '../../Loader';
import { useScreenContext, Screens } from '../../../Context/ScreenContext';
import { useSearchContext } from '../../../Context/SearchContext';
 
export function FormButtons() {
  const i18n = useI18nContext();
  const { resetForm, isValid, submitForm } =
    useFormContext<ManualAddCompanyFormData>();
  const [searchTerm, setSearchTerm] = useSearchContext();
  const { projectId, companyId } = useAddCompanyContext();
  const [, setCurrentScreen] = useScreenContext();
  const { isSuccess } = useAddToProject(companyId, projectId as string);
 
  return (
    <Modal.Footer>
      <Loader isLoading={isSuccess} />
      <Modal.FooterNotation>
        <Required showLabel />
      </Modal.FooterNotation>
      <Modal.FooterButtons>
        <Button
          variant="tertiary"
          onClick={() => {
            resetForm();
            setSearchTerm('');
          }}
          data-pendo="new-add-company-form-clear-button"
        >
          {i18n.t('views.generic.directory.add_company_package.clear')}
        </Button>
        {/*Update screen context to have a previous screen so that we can access that when we hit back*/}
        <Button
          variant="secondary"
          onClick={() =>
            setCurrentScreen((prevState) => {
              return {
                currentScreen: prevState.previousScreen as Screens,
                previousScreen: 'ManuallyAdd',
              };
            })
          }
          data-pendo="new-add-company-form-back-button"
        >
          {i18n.t('views.generic.directory.add_company_package.back')}
        </Button>
        <Button
          variant="primary"
          onClick={submitForm}
          disabled={!isValid}
          data-pendo="new-add-company-form-add-button"
        >
          {i18n.t('views.generic.directory.add_company_package.create')}
        </Button>
      </Modal.FooterButtons>
    </Modal.Footer>
  );
}