All files / app/src/shared/ui/back-button back-button.tsx

69.69% Statements 23/33
100% Branches 1/1
50% Functions 1/2
69.69% Lines 23/33

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 471x                     1x 6x   6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x                       6x 6x 6x   6x  
import { FC } from 'react'
import { Button } from '@tmk/ui-kit'
import BackArrow from '@/shared/assets/icons/common/back-arrow.svg'
import { useCancelModal } from '@/shared/hooks'
import { useTranslate } from '@/shared/lib'
 
export interface BackButtonProps {
  onClick?: () => void
  onClickWithAcceptance?: () => void
}
 
export const BackButton: FC<BackButtonProps> = ({ onClick, onClickWithAcceptance }) => {
  const { t } = useTranslate(['common'])
 
  const { CancelModal, openModal } = useCancelModal({
    modalData: {
      title: t('common:Undo_Changes'),
      description: t('common:The_actions_performed_and_the_data_filled_in_cannot_be_restored'),
      acceptAction: t('common:Accept'),
      declineAction: t('common:Back'),
    },
  })
  return (
    <>
      <CancelModal />
      <Button
        variant='border-icon'
        color='secondary'
        size='large'
        onClick={() => {
          if (onClick) {
            onClick()
          } else {
            openModal(() => {
              if (onClickWithAcceptance) {
                onClickWithAcceptance?.()
              }
            })
          }
        }}
      >
        <BackArrow className='stroke-currentColor' />
      </Button>
    </>
  )
}