Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions .storybook/preview.ts

This file was deleted.

31 changes: 31 additions & 0 deletions .storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from "react";
import { CssBaseline } from "@mui/material";
import type { Preview } from "@storybook/react";
import { themes } from "@storybook/theming";
import ThemeProvider from "../src/components/theme/theme-provider";

const preview: Preview = {
decorators: [
(Story) => {
return (
<ThemeProvider>
<CssBaseline />
<Story />
</ThemeProvider>
);
},
],
parameters: {
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/i,
},
},
docs: {
theme: themes.dark,
},
},
};

export default preview;
8 changes: 8 additions & 0 deletions playwright-tests/Login/login.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { test, expect } from "@playwright/test";

test("should have home title", async ({ page }) => {
//TODO: will remove this
await page.goto("/en");
const title = await page.title();
expect(title).toBe("Home");
});
83 changes: 83 additions & 0 deletions src/components/AlertModal/alertModal.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import type { Meta, StoryObj } from "@storybook/react";
import AlertModal from "./alertModal";
import { AlertModalProps } from "./types";

// Define the metadata for the component
const meta: Meta<AlertModalProps> = {
title: "Components/AlertModal",
component: AlertModal, // The component itself
argTypes: {
// Define controls for the props
severity: {
control: {
type: "select",
options: ["success", "info", "warning", "error"],
},
description:
"The severity of the alert modal, indicating its purpose or importance.",
},
horizontal: {
control: {
type: "select",
options: ["center", "left", "right"],
},
description: "The horizontal placement of the alert modal.",
},
vertical: {
control: {
type: "select",
options: ["bottom", "top"],
},
description: "The vertical placement of the alert modal.",
},
errorMessage: {
control: {
type: "text",
},
description: "The message displayed inside the alert modal.",
},
handleCloseAlertModal: {
control: false, // Disable the control as this is a function
description:
"Callback function triggered when the alert modal is closed.",
},
},
};

export default meta;

// Define the template for the stories
type Story = StoryObj<AlertModalProps>;

// Default story
export const Default: Story = {
args: {
handleCloseAlertModal: () => {},
},
};

// Story with custom message
export const CustomMessage: Story = {
args: {
...Default.args,
errorMessage: "This is custom message",
},
};

// Story with custom severity
export const CustomSeverity: Story = {
args: {
...Default.args,
errorMessage: "Login succesfully",
severity: "success",
},
};

// Story with custom placement
export const CustomPlacement: Story = {
args: {
...Default.args,
horizontal: "center",
vertical: "top",
},
};
27 changes: 27 additions & 0 deletions src/components/AlertModal/alertModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { FC } from "react";
import Snackbar from "@mui/material/Snackbar";
import { AlertModalProps } from "./types";
import { AlertContainer } from "./styled";

const AlertModal: FC<AlertModalProps> = ({
handleCloseAlertModal,
errorMessage = "Something wrong happened",
vertical = "top",
horizontal = "right",
severity = "error",
}) => {
return (
<Snackbar
open={!!errorMessage}
autoHideDuration={6000}
onClose={handleCloseAlertModal}
anchorOrigin={{ vertical: vertical, horizontal: horizontal }}
>
<AlertContainer onClose={handleCloseAlertModal} severity={severity}>
{errorMessage}
</AlertContainer>
</Snackbar>
);
};

export default AlertModal;
3 changes: 3 additions & 0 deletions src/components/AlertModal/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import AlertModal from "./alertModal";

export default AlertModal;
10 changes: 10 additions & 0 deletions src/components/AlertModal/styled.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Alert from "@mui/material/Alert";
import { styled, css } from "@mui/material/styles";

export const AlertContainer = styled(Alert, {
name: "AlertContainer",
})(
() => css`
width: 100%;
`
);
7 changes: 7 additions & 0 deletions src/components/AlertModal/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export type AlertModalProps = {
handleCloseAlertModal: () => void;
errorMessage?: string;
vertical?: "bottom" | "top";
horizontal?: "center" | "left" | "right";
severity?: "success" | "info" | "warning" | "error";
};
7 changes: 6 additions & 1 deletion src/components/theme/theme-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,24 @@
import {
createTheme,
ThemeProvider as MuiThemeProvider,
Shadows,
useTheme,
} from "@mui/material/styles";
import { useMemo, PropsWithChildren } from "react";

function ThemeProvider(props: PropsWithChildren<{}>) {
const defaultTheme = useTheme();

const theme = useMemo(
() =>
createTheme({
cssVariables: {
colorSchemeSelector: "class",
},
colorSchemes: { light: true, dark: true },
shadows: [...defaultTheme.shadows].map(() => "none") as Shadows,
}),
[]
[defaultTheme.shadows]
);

return <MuiThemeProvider theme={theme}>{props.children}</MuiThemeProvider>;
Expand Down
Loading