Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converting TicketShowHandler, NewReplyFrom and NotificationsBell into functional components #5411

43 changes: 20 additions & 23 deletions app/assets/javascripts/components/nav/notifications_bell.jsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,32 @@
import React from 'react';
import React, { useEffect, useState } from 'react';
import request from '../../utils/request';

export default class NotificationsBell extends React.Component {
constructor() {
super();
this.state = { open_tickets: false, requested_accounts: false };
}
const NotificationsBell = () => {
const [hasOpenTickets, setHasOpenTickets] = useState(false);
const [hasRequestedAccounts, setHasRequestedAccounts] = useState(false);

componentDidMount() {
useEffect(() => {
const main = document.getElementById('main');
const userId = main ? main.dataset.userId : null;

if (Features.wikiEd && userId) {
request(`/td/open_tickets?owner_id=${userId}`)
.then(res => res.json())
.then(({ open_tickets }) => this.setState({ open_tickets }))
.then(({ open_tickets }) => setHasOpenTickets(open_tickets))
.catch(err => err);
}

request('/requested_accounts.json')
.then(res => res.json())
.then(({ requested_accounts }) => this.setState({ requested_accounts }))
.then(({ requested_accounts }) => setHasRequestedAccounts(requested_accounts))
.catch(err => err); // If this errors, we're going to ignore it
}
}, []);

render() {
const path = Features.wikiEd ? '/admin' : '/requested_accounts';
return (
<li aria-describedby="notification-message" className="notifications">
<a href={path} className="icon icon-notifications_bell"/>
{
(this.state.requested_accounts || this.state.open_tickets)
const path = Features.wikiEd ? '/admin' : '/requested_accounts';
return (
<li aria-describedby="notification-message" className="notifications">
<a href={path} className="icon icon-notifications_bell" />
{
(hasRequestedAccounts || hasOpenTickets)
? (
<span className="bubble red">
<span id="notification-message" className="screen-reader">You have new notifications.</span>
Expand All @@ -39,8 +35,9 @@ export default class NotificationsBell extends React.Component {
: (
<span id="notification-message" className="screen-reader">You have no new notifications.</span>
)
}
</li>
);
}
}
}
</li>
);
};

export default (NotificationsBell);
Loading