The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Refactor/modal component tests 1332 (#1392)
Mustajab Ikrambd2e4307d211
diff --git a/front/src/modules/spreadsheet-import/components/ModalWrapper.tsx b/front/src/modules/spreadsheet-import/components/ModalWrapper.tsxindex 8a136e81bd7..60e47cb875a 100644--- a/front/src/modules/spreadsheet-import/components/ModalWrapper.tsx+++ b/front/src/modules/spreadsheet-import/components/ModalWrapper.tsx@@ -37,7 +37,7 @@ export const ModalWrapper = ({ children, isOpen, onClose }: Props) => {const { rtl } = useSpreadsheetImportInternal();return (- <StyledModal isOpen={isOpen}>+ <StyledModal isOpen={isOpen} size="large"><StyledRtlLtr dir={rtl ? 'rtl' : 'ltr'}><ModalCloseButton onClose={onClose} />{children}diff --git a/front/src/modules/ui/modal/components/Modal.tsx b/front/src/modules/ui/modal/components/Modal.tsxindex 204c7252078..a326249209e 100644--- a/front/src/modules/ui/modal/components/Modal.tsx+++ b/front/src/modules/ui/modal/components/Modal.tsx@@ -12,14 +12,46 @@ import {import { ModalHotkeyScope } from './types/ModalHotkeyScope';-const StyledModalDiv = styled(motion.div)`+const StyledModalDiv = styled(motion.div)<{+ size?: ModalSize;+ padding?: ModalPadding;+}>`display: flex;flex-direction: column;background: ${({ theme }) => theme.background.primary};+ color: ${({ theme }) => theme.font.color.primary};border-radius: ${({ theme }) => theme.border.radius.md};overflow: hidden;max-height: 90vh;z-index: 10000; // should be higher than Backdrop's z-index++ width: ${({ size, theme }) => {+ switch (size) {+ case 'small':+ return theme.modal.size.sm;+ case 'medium':+ return theme.modal.size.md;+ case 'large':+ return theme.modal.size.lg;+ default:+ return 'auto';+ }+ }};++ padding: ${({ padding, theme }) => {+ switch (padding) {+ case 'none':+ return theme.spacing(0);+ case 'small':+ return theme.spacing(2);+ case 'medium':+ return theme.spacing(4);+ case 'large':+ return theme.spacing(6);+ default:+ return 'auto';+ }+ }};`;const StyledHeader = styled.div`@@ -85,12 +117,17 @@ function ModalFooter({ children, ...restProps }: ModalFooterProps) {/*** Modal*/+export type ModalSize = 'small' | 'medium' | 'large';+export type ModalPadding = 'none' | 'small' | 'medium' | 'large';+type ModalProps = React.PropsWithChildren &React.ComponentProps<'div'> & {isOpen?: boolean;onClose?: () => void;hotkeyScope?: ModalHotkeyScope;onEnter?: () => void;+ size?: ModalSize;+ padding?: ModalPadding;};const modalVariants = {@@ -105,6 +142,8 @@ export function Modal({onClose,hotkeyScope = ModalHotkeyScope.Default,onEnter,+ size = 'medium',+ padding = 'medium',...restProps}: ModalProps) {const modalRef = useRef<HTMLDivElement>(null);@@ -157,6 +196,8 @@ export function Modal({// eslint-disable-next-line @typescript-eslint/ban-ts-comment// @ts-ignoreref={modalRef}+ size={size}+ padding={padding}initial="hidden"animate="visible"exit="exit"diff --git a/front/src/modules/ui/modal/components/__stories__/Modal.stories.tsx b/front/src/modules/ui/modal/components/__stories__/Modal.stories.tsxindex cd7e461d215..994ef085a7c 100644--- a/front/src/modules/ui/modal/components/__stories__/Modal.stories.tsx+++ b/front/src/modules/ui/modal/components/__stories__/Modal.stories.tsx@@ -1,39 +1,40 @@-import styled from '@emotion/styled';-import { Meta, StoryObj } from '@storybook/react';+import type { Meta, StoryObj } from '@storybook/react';import { ComponentDecorator } from '~/testing/decorators/ComponentDecorator';import { Modal } from '../Modal';+import { ModalHotkeyScope } from '../types/ModalHotkeyScope';const meta: Meta<typeof Modal> = {title: 'UI/Modal/Modal',component: Modal,- decorators: [ComponentDecorator],};-export default meta;+export default meta;type Story = StoryObj<typeof Modal>;-const StyledContentContainer = styled.div`- color: ${({ theme }) => theme.font.color.primary};- margin: 5px;- padding: ${({ theme }) => theme.spacing(10)};-`;--const args = {- isOpen: true,- children: (- <Modal.Content>- <StyledContentContainer>Lorem ipsum</StyledContentContainer>- </Modal.Content>- ),-};-export const Default: Story = {- args,+ args: {+ isOpen: true,+ size: 'medium',+ padding: 'medium',+ hotkeyScope: ModalHotkeyScope.Default,+ children: (+ <>+ <Modal.Header>Stay in touch</Modal.Header>+ <Modal.Content>+ This is a dummy newletter form so don't bother trying to test it. Not+ that I expect you to, anyways. :)+ </Modal.Content>+ <Modal.Footer>+ By using Twenty, you're opting for the finest CRM experience you'll+ ever encounter.+ </Modal.Footer>+ </>+ ),+ },decorators: [ComponentDecorator],-};--Default.argTypes = {- children: { control: false },+ argTypes: {+ children: { control: false },+ },};diff --git a/front/src/modules/ui/theme/constants/modal.ts b/front/src/modules/ui/theme/constants/modal.tsnew file mode 100644index 00000000000..30099fde891--- /dev/null+++ b/front/src/modules/ui/theme/constants/modal.ts@@ -0,0 +1,7 @@+export const modal = {+ size: {+ sm: '300px',+ md: '400px',+ lg: '53%',+ },+};diff --git a/front/src/modules/ui/theme/constants/theme.ts b/front/src/modules/ui/theme/constants/theme.tsindex 3239f423dc0..4867e524ca1 100644--- a/front/src/modules/ui/theme/constants/theme.ts+++ b/front/src/modules/ui/theme/constants/theme.ts@@ -7,6 +7,7 @@ import { boxShadowDark, boxShadowLight } from './boxShadow';import { color, grayScale } from './colors';import { fontDark, fontLight } from './font';import { icon } from './icon';+import { modal } from './modal';import { tagDark, tagLight } from './tag';import { text } from './text';@@ -14,6 +15,7 @@ const common = {color: color,grayScale: grayScale,icon: icon,+ modal: modal,text: text,blur: blur,animation: animation,