All files / src/features/MerchantPortal/MerchantSettings/components atomsV2.tsx

90.9% Statements 10/11
100% Branches 6/6
75% Functions 3/4
100% Lines 8/8

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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102              11x                                             11x             383x   383x 76x                                             11x                         383x                     76x                            
import { Box, BoxProps, SxProps } from "@mui/material";
import { ButtonProps } from "@common/Button/Button";
import React from "react";
import { styled } from "@theme/v2/Provider";
import { useCustomThemeV2 } from "@theme/hooks/useCustomThemeV2";
import GiveButton from "@shared/Button/GiveButton";
 
export const BusinessSectionContainer = styled(Box)(({ theme }) => ({
  marginTop: 2,
  width: "100%",
  padding: "24px 16px",
 
  [theme.breakpoints.down("sm")]: {
    padding: "12px 8px",
  },
}));
 
type TAction = ButtonProps & {
  label: string;
};
 
type TFormActions = {
  primaryAction: TAction;
  secondaryAction: TAction;
  formName: string;
  // Per-screen overrides for the bar's own box. Defaults are unchanged, so
  // existing settings screens keep the geometry they were built against.
  actionsSx?: SxProps;
};
 
const FormActions = ({
  primaryAction,
  secondaryAction,
  formName,
  isDirty,
  actionsSx,
}: TFormActions & { isDirty: boolean }) => {
  const { isDesktopView } = useCustomThemeV2();
 
  if (!isDirty) return null;
  return (
    <ActionsContainer mt={isDesktopView ? 2 : 3.5} sx={actionsSx}>
      <GiveButton
        size="large"
        variant="ghost"
        onClick={secondaryAction.onClick}
        label={secondaryAction.label}
        disabled={secondaryAction.disabled}
        data-testid="discard-form-action-button"
      />
      <GiveButton
        size="large"
        type="submit"
        variant="filled"
        form={formName}
        disabled={primaryAction.disabled}
        label={primaryAction.label}
        data-testid="save-form-action-button"
      />
    </ActionsContainer>
  );
};
 
export const SettingsFormWrapperV2 = ({
  children,
  formActions,
  formProps,
  isDirty,
  ...rest
}: {
  children: React.ReactNode;
  formActions: TFormActions;
  formProps: BoxProps;
  isDirty: boolean;
  sx?: SxProps;
}) => {
  return (
    <Box component="form" id={formActions.formName} {...formProps}>
      <Box sx={{ marginBottom: "30px", ...(rest.sx && { ...rest.sx }) }}>
        {children}
      </Box>
 
      <FormActions {...formActions} isDirty={isDirty} />
    </Box>
  );
};
 
const ActionsContainer = styled(Box)(({ theme }) => ({
  display: "flex",
  justifyContent: "flex-end",
  gap: "12px",
  padding: "16px 20px 10px 20px",
  borderTop: `1px solid ${theme.palette?.border?.primary}`,
  background: theme.palette.surface?.["primary-transparent"],
  backdropFilter: "blur(8px)", // same blur used in table pagination (agreed with design team)
  position: "fixed",
  width: "100vw",
  bottom: 0,
  left: 0,
  zIndex: 10,
}));