diff --git a/client/src/actions/index.js b/client/src/actions/index.js index 3087c47d..28c2a713 100644 --- a/client/src/actions/index.js +++ b/client/src/actions/index.js @@ -213,6 +213,21 @@ export const getClients = () => async (dispatch) => { } }; +export const getProfileRequest = createAction('GET_PROFILE_REQUEST'); +export const getProfileFailure = createAction('GET_PROFILE_FAILURE'); +export const getProfileSuccess = createAction('GET_PROFILE_SUCCESS'); + +export const getProfile = () => async (dispatch) => { + dispatch(getProfileRequest()); + try { + const profile = await apiClient.getProfile(); + dispatch(getProfileSuccess(profile)); + } catch (error) { + dispatch(addErrorToast({ error })); + dispatch(getProfileFailure()); + } +}; + export const dnsStatusRequest = createAction('DNS_STATUS_REQUEST'); export const dnsStatusFailure = createAction('DNS_STATUS_FAILURE'); export const dnsStatusSuccess = createAction('DNS_STATUS_SUCCESS'); @@ -224,6 +239,7 @@ export const getDnsStatus = () => async (dispatch) => { dispatch(dnsStatusSuccess(dnsStatus)); dispatch(getVersion()); dispatch(getTlsStatus()); + dispatch(getProfile()); } catch (error) { dispatch(addErrorToast({ error })); dispatch(dnsStatusFailure()); diff --git a/client/src/api/Api.js b/client/src/api/Api.js index c5ced2b8..470577a8 100644 --- a/client/src/api/Api.js +++ b/client/src/api/Api.js @@ -525,6 +525,14 @@ class Api { }; return this.makeRequest(path, method, config); } + + // Profile + GET_PROFILE = { path: 'profile', method: 'GET' }; + + getProfile() { + const { path, method } = this.GET_PROFILE; + return this.makeRequest(path, method); + } } const apiClient = new Api(); diff --git a/client/src/components/Header/index.js b/client/src/components/Header/index.js index 28fa0767..8d16e614 100644 --- a/client/src/components/Header/index.js +++ b/client/src/components/Header/index.js @@ -60,9 +60,11 @@ class Header extends Component { />
- - sign_out - + {!dashboard.processingProfile && dashboard.name && + + sign_out + + }
diff --git a/client/src/reducers/index.js b/client/src/reducers/index.js index 589da42e..0e8ff407 100644 --- a/client/src/reducers/index.js +++ b/client/src/reducers/index.js @@ -189,6 +189,14 @@ const dashboard = handleActions( processingDnsSettings: false, }; }, + + [actions.getProfileRequest]: state => ({ ...state, processingProfile: true }), + [actions.getProfileFailure]: state => ({ ...state, processingProfile: false }), + [actions.getProfileSuccess]: (state, { payload }) => ({ + ...state, + name: payload.name, + processingProfile: false, + }), }, { processing: true, @@ -198,6 +206,7 @@ const dashboard = handleActions( processingClients: true, processingUpdate: false, processingDnsSettings: true, + processingProfile: true, upstreamDns: '', bootstrapDns: '', allServers: false, @@ -209,6 +218,7 @@ const dashboard = handleActions( dnsVersion: '', clients: [], autoClients: [], + name: '', }, );