2024-08-29 11:26:43 -07:00
|
|
|
import Button from "react-bootstrap/Button";
|
2024-08-29 11:41:41 -07:00
|
|
|
import Col from "react-bootstrap/Col";
|
2024-08-29 11:26:43 -07:00
|
|
|
import Container from "react-bootstrap/Container";
|
2024-08-29 11:41:41 -07:00
|
|
|
import Form from "react-bootstrap/Form";
|
2024-08-28 19:25:20 -07:00
|
|
|
import Placeholder from "react-bootstrap/Placeholder";
|
2024-08-29 10:27:00 -07:00
|
|
|
import React from "react";
|
2024-08-29 11:26:43 -07:00
|
|
|
import Row from "react-bootstrap/Row";
|
2024-08-28 19:25:20 -07:00
|
|
|
|
|
|
|
import Client from "./client/Client";
|
2024-08-29 11:26:43 -07:00
|
|
|
import EmailContentHTML from "./EmailContentHTML";
|
|
|
|
import EmailContentText from "./EmailContentText";
|
2024-08-28 19:25:20 -07:00
|
|
|
import { IAccount, IEmail } from "./client/types";
|
|
|
|
|
|
|
|
type EmailContentProps = {
|
|
|
|
account: IAccount | null;
|
|
|
|
client: Client | null;
|
|
|
|
email: IEmail | null;
|
|
|
|
emailId: string;
|
|
|
|
};
|
|
|
|
|
2024-08-29 11:26:43 -07:00
|
|
|
type EmailContentState = {
|
|
|
|
showHTML: boolean;
|
|
|
|
};
|
2024-08-28 19:25:20 -07:00
|
|
|
|
|
|
|
class EmailContent extends React.Component<
|
|
|
|
EmailContentProps,
|
|
|
|
EmailContentState
|
|
|
|
> {
|
2024-08-29 11:26:43 -07:00
|
|
|
state = {
|
|
|
|
showHTML: false,
|
|
|
|
};
|
|
|
|
|
2024-08-28 19:25:20 -07:00
|
|
|
componentDidMount() {
|
|
|
|
this.ensureData();
|
|
|
|
}
|
|
|
|
componentDidUpdate() {
|
|
|
|
this.ensureData();
|
|
|
|
}
|
|
|
|
|
|
|
|
ensureData() {
|
|
|
|
if (this.props.account == null) return;
|
|
|
|
if (this.props.client == null) return;
|
|
|
|
this.props.client.ensureEmailContent(
|
|
|
|
this.props.account.id,
|
|
|
|
this.props.emailId,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2024-08-29 10:27:00 -07:00
|
|
|
const email = this.props.email;
|
|
|
|
if (email == null || email.bodyValues == null) {
|
2024-08-28 19:25:20 -07:00
|
|
|
return <Placeholder />;
|
2024-08-29 11:26:43 -07:00
|
|
|
}
|
|
|
|
let content;
|
|
|
|
if (this.state.showHTML) {
|
|
|
|
if (email.htmlBody != null) {
|
|
|
|
content = <EmailContentHTML email={email} />;
|
|
|
|
} else {
|
|
|
|
return <p>No HTML content</p>;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (email.textBody != null) {
|
|
|
|
content = <EmailContentText email={email} />;
|
|
|
|
} else {
|
|
|
|
return <p>No text content/</p>;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<Container fluid>
|
2024-08-29 11:41:41 -07:00
|
|
|
<Row>
|
|
|
|
<Form>
|
|
|
|
<Form.Group
|
|
|
|
as={Row}
|
|
|
|
className="mb-3"
|
|
|
|
controlId="formHorizontalEmail"
|
|
|
|
>
|
|
|
|
<Form.Label column sm={2}>
|
|
|
|
From
|
|
|
|
</Form.Label>
|
|
|
|
<Col sm={10}>
|
|
|
|
<p>
|
|
|
|
{email.from == null
|
|
|
|
? "unknown"
|
|
|
|
: email.from.map((f) => f.name)}
|
|
|
|
</p>
|
|
|
|
</Col>
|
|
|
|
<Form.Label column sm={2}>
|
|
|
|
Received
|
|
|
|
</Form.Label>
|
|
|
|
<Col sm={10}>{email.receivedAt}</Col>
|
|
|
|
</Form.Group>
|
|
|
|
</Form>
|
|
|
|
</Row>
|
2024-08-29 11:26:43 -07:00
|
|
|
<Row>
|
|
|
|
<Button
|
|
|
|
onClick={() => {
|
|
|
|
this.switchDisplay();
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
Switch
|
|
|
|
</Button>
|
|
|
|
</Row>
|
|
|
|
<Row>{content}</Row>
|
|
|
|
</Container>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
switchDisplay() {
|
|
|
|
if (this.state.showHTML) {
|
|
|
|
this.setState({
|
|
|
|
showHTML: false,
|
|
|
|
});
|
2024-08-28 19:25:20 -07:00
|
|
|
} else {
|
2024-08-29 11:26:43 -07:00
|
|
|
this.setState({
|
|
|
|
showHTML: true,
|
|
|
|
});
|
2024-08-28 19:25:20 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
export default EmailContent;
|