From 3cca6be0000c1224ec0bbde710d369eb4bb90f1c Mon Sep 17 00:00:00 2001 From: Andrew Watkins Date: Thu, 12 Dec 2019 14:09:17 -0800 Subject: [PATCH] feat: route user to no orgs page (#16208) * feat: route user to no orgs page * style: no orgs page * fix: eslint * fix: prettier --- ui/cypress/e2e/orgs.test.ts | 21 ++++++++ ui/cypress/index.d.ts | 2 + ui/cypress/support/commands.ts | 8 +++ ui/src/index.tsx | 2 + .../organizations/containers/NoOrgsPage.tsx | 49 +++++++++++++++++++ ui/src/shared/containers/RouteToOrg.tsx | 7 ++- 6 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 ui/cypress/e2e/orgs.test.ts create mode 100644 ui/src/organizations/containers/NoOrgsPage.tsx diff --git a/ui/cypress/e2e/orgs.test.ts b/ui/cypress/e2e/orgs.test.ts new file mode 100644 index 0000000000..99d8baeb42 --- /dev/null +++ b/ui/cypress/e2e/orgs.test.ts @@ -0,0 +1,21 @@ +describe('Orgs', () => { + beforeEach(() => { + cy.flush() + }) + + describe('when there is a user with no orgs', () => { + beforeEach(() => { + cy.signin().then(({body}) => { + cy.deleteOrg(body.org.id) + }) + + cy.visit('/') + }) + + it('forwards the user to the No Orgs Page', () => { + cy.url().should('contain', 'no-org') + cy.contains('Sign In').click() + cy.url().should('contain', 'signin') + }) + }) +}) diff --git a/ui/cypress/index.d.ts b/ui/cypress/index.d.ts index c255b24c4f..05e739055a 100644 --- a/ui/cypress/index.d.ts +++ b/ui/cypress/index.d.ts @@ -8,6 +8,7 @@ import { createCell, createOrg, createSource, + deleteOrg, flush, getByTestID, getByInputName, @@ -48,6 +49,7 @@ declare global { createDashWithViewAndVar: typeof createDashWithViewAndVar createView: typeof createView createOrg: typeof createOrg + deleteOrg: typeof deleteOrg flush: typeof flush getByTestID: typeof getByTestID getByInputName: typeof getByInputName diff --git a/ui/cypress/support/commands.ts b/ui/cypress/support/commands.ts index 49e69a56bc..8fbdc5cd5a 100644 --- a/ui/cypress/support/commands.ts +++ b/ui/cypress/support/commands.ts @@ -123,6 +123,13 @@ export const createOrg = (): Cypress.Chainable => { }) } +export const deleteOrg = (id: string): Cypress.Chainable => { + return cy.request({ + method: 'DELETE', + url: `/api/v2/orgs/${id}`, + }) +} + export const createBucket = ( orgID?: string, organization?: string, @@ -452,6 +459,7 @@ Cypress.Commands.add('createView', createView) // orgs Cypress.Commands.add('createOrg', createOrg) +Cypress.Commands.add('deleteOrg', deleteOrg) // buckets Cypress.Commands.add('createBucket', createBucket) diff --git a/ui/src/index.tsx b/ui/src/index.tsx index ac764439da..7e3bf1bd2e 100644 --- a/ui/src/index.tsx +++ b/ui/src/index.tsx @@ -88,6 +88,7 @@ import NewRuleOverlay from 'src/alerting/components/notifications/NewRuleOverlay import EditRuleOverlay from 'src/alerting/components/notifications/EditRuleOverlay' import NewEndpointOverlay from 'src/alerting/components/endpoints/NewEndpointOverlay' import EditEndpointOverlay from 'src/alerting/components/endpoints/EditEndpointOverlay' +import NoOrgsPage from 'src/organizations/containers/NoOrgsPage' // Overlays import OverlayHandler, { @@ -196,6 +197,7 @@ class Root extends PureComponent { + diff --git a/ui/src/organizations/containers/NoOrgsPage.tsx b/ui/src/organizations/containers/NoOrgsPage.tsx new file mode 100644 index 0000000000..31ccd12ed9 --- /dev/null +++ b/ui/src/organizations/containers/NoOrgsPage.tsx @@ -0,0 +1,49 @@ +// Libraries +import React, {FC} from 'react' +import {FunnelPage, Button, ComponentColor} from '@influxdata/clockface' +import {withRouter, WithRouterProps} from 'react-router' +import {connect} from 'react-redux' + +// Types +import {AppState} from 'src/types' + +interface DispatchProps { + me: AppState['me'] +} + +type Props = DispatchProps & WithRouterProps + +const NoOrgsPage: FC = ({router, me}) => { + const handleClick = () => { + router.push('/signin') + } + + return ( + +
+ +
+

Whoops!

+

+ You don't belong to an organization. +
+ Add user {`"${me.name}"`} to an organization to + continue +

+