aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/settings/navigation/SettingsNavigation.tsx
blob: 66763c6a6bb93be5b81be9a60f077c1630736392 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
import { Component } from 'react';
import { defineMessages, injectIntl, WrappedComponentProps } from 'react-intl';
import { inject, observer } from 'mobx-react';
import { NavLink } from 'react-router-dom';
import { StoresProps } from '../../../@types/ferdium-components.types';
import {
  LOCAL_SERVER,
  LIVE_FERDIUM_API,
  LIVE_FRANZ_API,
} from '../../../config';
import globalMessages from '../../../i18n/globalMessages';

const messages = defineMessages({
  availableServices: {
    id: 'settings.navigation.availableServices',
    defaultMessage: 'Available services',
  },
  yourServices: {
    id: 'settings.navigation.yourServices',
    defaultMessage: 'Your services',
  },
  yourWorkspaces: {
    id: 'settings.navigation.yourWorkspaces',
    defaultMessage: 'Your workspaces',
  },
  account: {
    id: 'settings.navigation.account',
    defaultMessage: 'Account',
  },
  team: {
    id: 'settings.navigation.team',
    defaultMessage: 'Manage Team',
  },
  releaseNotes: {
    id: 'settings.navigation.releaseNotes',
    defaultMessage: 'Release Notes',
  },
  supportFerdium: {
    id: 'settings.navigation.supportFerdium',
    defaultMessage: 'About Ferdium',
  },
  logout: {
    id: 'settings.navigation.logout',
    defaultMessage: 'Logout',
  },
});

interface IProps extends Partial<StoresProps>, WrappedComponentProps {
  serviceCount: number;
  workspaceCount: number;
}

@inject('stores', 'actions')
@observer
class SettingsNavigation extends Component<IProps> {
  handleLogout(): void {
    const isUsingWithoutAccount =
      this.props.stores!.settings.app.server === LOCAL_SERVER;

    // Remove current auth token
    localStorage.removeItem('authToken');

    if (isUsingWithoutAccount) {
      // Reset server back to Ferdium API
      this.props.actions!.settings.update({
        type: 'app',
        data: {
          server: LIVE_FERDIUM_API,
        },
      });
    }
    this.props.stores!.user.isLoggingOut = true;

    this.props.stores!.router.push('/auth/welcome');

    // Reload Ferdium, otherwise many settings won't sync correctly with the server
    // after logging into another account
    window.location.reload();
  }

  render() {
    const { serviceCount, workspaceCount, stores, intl } = this.props;
    const isUsingWithoutAccount = stores!.settings.app.server === LOCAL_SERVER;
    const isUsingFranzServer = stores!.settings.app.server === LIVE_FRANZ_API;

    return (
      <div className="settings-navigation">
        <NavLink
          to="/settings/recipes"
          className={({ isActive }) =>
            isActive
              ? 'settings-navigation__link is-active'
              : 'settings-navigation__link'
          }
        >
          {intl.formatMessage(messages.availableServices)}
        </NavLink>
        <NavLink
          to="/settings/services"
          className={({ isActive }) =>
            isActive
              ? 'settings-navigation__link is-active'
              : 'settings-navigation__link'
          }
        >
          {intl.formatMessage(messages.yourServices)}{' '}
          <span className="badge">{serviceCount}</span>
        </NavLink>
        <NavLink
          to="/settings/workspaces"
          className={({ isActive }) =>
            isActive
              ? 'settings-navigation__link is-active'
              : 'settings-navigation__link'
          }
        >
          {intl.formatMessage(messages.yourWorkspaces)}{' '}
          <span className="badge">{workspaceCount}</span>
        </NavLink>
        {!isUsingWithoutAccount && (
          <NavLink
            to="/settings/user"
            className={({ isActive }) =>
              isActive
                ? 'settings-navigation__link is-active'
                : 'settings-navigation__link'
            }
          >
            {intl.formatMessage(messages.account)}
          </NavLink>
        )}
        {isUsingFranzServer && (
          <NavLink
            to="/settings/team"
            className={({ isActive }) =>
              isActive
                ? 'settings-navigation__link is-active'
                : 'settings-navigation__link'
            }
          >
            {intl.formatMessage(messages.team)}
          </NavLink>
        )}
        <NavLink
          to="/settings/app"
          className={({ isActive }) =>
            isActive
              ? 'settings-navigation__link is-active'
              : 'settings-navigation__link'
          }
        >
          {intl.formatMessage(globalMessages.settings)}
          {stores!.settings.app.automaticUpdates &&
            (stores!.ui.showServicesUpdatedInfoBar ||
              stores!.app.updateStatus ===
                stores!.app.updateStatusTypes.AVAILABLE ||
              stores!.app.updateStatus ===
                stores!.app.updateStatusTypes.DOWNLOADED) && (
              <span className="update-available">•</span>
            )}
        </NavLink>
        <NavLink
          to="/settings/releasenotes"
          className={({ isActive }) =>
            isActive
              ? 'settings-navigation__link is-active'
              : 'settings-navigation__link'
          }
        >
          {intl.formatMessage(messages.releaseNotes)}
        </NavLink>
        <NavLink
          to="/settings/support"
          className={({ isActive }) =>
            isActive
              ? 'settings-navigation__link is-active'
              : 'settings-navigation__link'
          }
        >
          {intl.formatMessage(messages.supportFerdium)}
        </NavLink>
        <span className="settings-navigation__expander" />
        <button
          type="button"
          // @ts-expect-error  Fix me
          to="/auth/logout" // TODO: [TS DEBT] Need to check if button take this prop
          className="settings-navigation__link"
          onClick={this.handleLogout.bind(this)}
        >
          {isUsingWithoutAccount
            ? 'Exit session'
            : intl.formatMessage(messages.logout)}
        </button>
      </div>
    );
  }
}

export default injectIntl(SettingsNavigation);