Read all notifications functionnality

This commit is contained in:
Maxime Lalo 2023-10-09 10:59:19 +02:00
parent 150ff1c2c3
commit 2cbc2c3e20
4 changed files with 26 additions and 3 deletions

View File

@ -30,6 +30,15 @@
cursor: pointer; cursor: pointer;
} }
} }
.notification-subheader {
width: 100%;
display: inline-flex;
justify-content: space-between;
text-decoration: underline;
cursor: pointer;
}
.notification-body { .notification-body {
margin-top: 24px; margin-top: 24px;
overflow: hidden; overflow: hidden;

View File

@ -37,10 +37,12 @@ export default class NotificationModal extends React.Component<IProps, IState> {
<Image src={CloseIcon} alt="Close notification modal" className={classes["close-icon"]}></Image> <Image src={CloseIcon} alt="Close notification modal" className={classes["close-icon"]}></Image>
</div> </div>
</div> </div>
; <div className={classes["notification-subheader"]} onClick={this.readAllNotifications}>
<Typography typo={ITypo.CAPTION_14}>Tout marquer comme lu</Typography>
</div>
<div className={classes["notification-body"]}> <div className={classes["notification-body"]}>
<> <>
{Toasts.getInstance().toasts.length === 0 ? ( {!this.state.toastList || this.state.toastList.length === 0 ? (
<div className={classes["missing-notification"]}> <div className={classes["missing-notification"]}>
<Typography typo={ITypo.P_18} color={ITypoColor.GREY}> <Typography typo={ITypo.P_18} color={ITypoColor.GREY}>
Vous n'avez pas de notifications. Vous n'avez pas de notifications.
@ -64,6 +66,10 @@ export default class NotificationModal extends React.Component<IProps, IState> {
this.removeOnToastChange(); this.removeOnToastChange();
} }
private readAllNotifications() {
Toasts.getInstance().closeAll();
}
private handleToastChange(toastList: IToast[] | null) { private handleToastChange(toastList: IToast[] | null) {
this.setState({ this.setState({
toastList, toastList,

View File

@ -109,7 +109,6 @@ class ToastElementClass extends React.Component<IPropsClass, IState> {
} }
private async handleClick(e: React.MouseEvent) { private async handleClick(e: React.MouseEvent) {
console.log('redirectUrl', this.props.toast.redirectUrl);
if (this.props.toast.redirectUrl) { if (this.props.toast.redirectUrl) {
this.onClose(e); this.onClose(e);
await this.props.router.push(this.props.toast.redirectUrl); await this.props.router.push(this.props.toast.redirectUrl);

View File

@ -97,6 +97,15 @@ export default class Toasts {
this.event.emit("change", this.toastList); this.event.emit("change", this.toastList);
} }
public async closeAll() {
for (let i = 0; i < this.toastList.length; i++) {
await Notifications.getInstance().put(this.toastList[i]?.uid as string, {
read: true,
});
}
this.event.emit("change", []);
}
/** /**
* An utility static method you can use to quickly display an error toast * An utility static method you can use to quickly display an error toast
* with a custom error message. * with a custom error message.