saleor-dashboard/src/components/Timeline/TimelineNote.tsx
Jonatan Witoszek 13ca6bbba8
Remove transactions feature flag (#3557)
* Update schema, remove transaction specific files

* Merge `.transaction` queries and mutations into regular files

* Merge OrderDetails fragments

* Remove usage of `.transaction` graphl types

* Update fixtures

* Remove usage of useFlag, remove duplicated queries & mutations

* Fix displayed event type for INFO

* Remove type alias from order/types.ts, remove type casting

* Fix failing tests

* Add preview label and better description in Channel settings

* Update button in GrantRefund page

* Fix missing data-test-id

* Extract messages

* Visual fixes

* Revert changes to generated files

* Revert changes to generated files

* Fix psp reference hover

* Fix colors on manu refunds screen

* Revert "Fix colors on manu refunds screen"

This reverts commit 02302930ab502a4fdc3c71558532a2d74f2e32c9.

---------

Co-authored-by: andrzejewsky <vox3r69@gmail.com>
Co-authored-by: Michal Miszczyszyn <michal@mmiszy.pl>
2023-04-28 13:24:10 +02:00

113 lines
2.6 KiB
TypeScript

import { useUser } from "@dashboard/auth";
import { getUserInitials } from "@dashboard/misc";
import { Card, CardContent, Typography } from "@material-ui/core";
import { makeStyles } from "@saleor/macaw-ui";
import { vars } from "@saleor/macaw-ui/next";
import React from "react";
import { DateTime } from "../Date";
import { UserAvatar } from "../UserAvatar";
const useStyles = makeStyles(
theme => ({
avatar: {
left: -40,
position: "absolute",
top: 0,
},
card: {
marginBottom: theme.spacing(3),
position: "relative",
boxShadow: "none",
background: vars.colors.background.surfaceNeutralPlain,
},
cardContent: {
wordBreak: "break-all",
borderRadius: "4px",
border: `1px solid ${vars.colors.border.neutralDefault}`,
"&:last-child": {
padding: 16,
},
},
root: {
position: "relative",
},
title: {
"& p": {
fontSize: "14px",
},
alignItems: "center",
display: "flex",
justifyContent: "space-between",
marginBottom: theme.spacing(),
},
}),
{ name: "TimelineNote" },
);
interface TimelineNoteProps {
date: string;
message: string | null;
user: {
email: string;
firstName?: string;
lastName?: string;
};
hasPlainDate?: boolean;
}
interface NoteMessageProps {
message: string;
}
const NoteMessage: React.FC<NoteMessageProps> = ({ message }) => (
<>
{message.split("\n").map(string => {
if (string === "") {
return <br />;
}
return <Typography>{string}</Typography>;
})}
</>
);
export const TimelineNote: React.FC<TimelineNoteProps> = props => {
const { date, user, message, hasPlainDate } = props;
const { user: currentUser } = useUser();
const classes = useStyles(props);
const getUserTitleOrEmail = () => {
if (user?.firstName && user?.lastName) {
return `${user.firstName} ${user.lastName}`;
}
return user?.email;
};
return (
<div className={classes.root}>
{user && (
<UserAvatar
initials={getUserInitials(currentUser)}
url={currentUser?.avatar?.url}
className={classes.avatar}
/>
)}
<div className={classes.title}>
<Typography>{getUserTitleOrEmail()}</Typography>
<Typography>
<DateTime date={date} plain={hasPlainDate} />
</Typography>
</div>
<Card className={classes.card} elevation={16}>
<CardContent className={classes.cardContent}>
<NoteMessage message={message} />
</CardContent>
</Card>
</div>
);
};
TimelineNote.displayName = "TimelineNote";
export default TimelineNote;