Skip to content

Commit

Permalink
Start adding registration and authentication features to dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
koredefashokun committed May 8, 2020
1 parent 8904548 commit be5b74c
Show file tree
Hide file tree
Showing 20 changed files with 2,547 additions and 151 deletions.
13 changes: 12 additions & 1 deletion api/src/models/Item.ts
@@ -1,11 +1,18 @@
import { model, Schema, Document } from 'mongoose';
import { StoreDocument } from './Store';

enum ItemUnit {
Kilogram = 'Kilogram',
Litre = 'Litre'
}

export interface ItemDocument extends Document {
name: string;
storeId: string;
store: StoreDocument;
unit: string;
pricePerUnit: number;
featured: boolean;
}

const ItemSchema = new Schema(
Expand All @@ -21,11 +28,15 @@ const ItemSchema = new Schema(
},
unit: {
type: String,
enum: ['']
enum: Object.values(ItemUnit)
},
pricePerUnit: {
type: Number,
required: true
},
featured: {
type: Boolean,
default: false
}
},
{ timestamps: true }
Expand Down
4 changes: 2 additions & 2 deletions api/src/models/Store.ts
Expand Up @@ -16,10 +16,10 @@ const StoreSchema = new Schema(
websiteUrl: {
type: String
},
instagramUrl: {
instagramUsername: {
type: String
},
twitterUrl: {
twitterUsername: {
type: String
}
},
Expand Down
12 changes: 9 additions & 3 deletions api/src/schema.ts
Expand Up @@ -5,16 +5,19 @@ import UserType from './types/User';
import ItemType from './types/Item';
import OrderType from './types/Order';
import StoreType from './types/Store';
import ManagerType from './types/Manager';

import * as userMutations from './mutations/users';
import * as itemMutations from './mutations/items';
import * as orderMutations from './mutations/orders';
import * as storeMutations from './mutations/stores';
import * as managerMutations from './mutations/managers';

import * as userQueries from './queries/users';
import * as itemQueries from './queries/items';
import * as orderQueries from './queries/orders';
import * as storeQueries from './queries/stores';
import * as managerQueries from './queries/managers';

const RootType = `
type Mutation { default: String }
Expand All @@ -27,21 +30,24 @@ const typeDefs = [
UserType,
ItemType,
OrderType,
StoreType
StoreType,
ManagerType
];

const resolvers = {
Mutation: {
...userMutations,
...itemMutations,
...orderMutations,
...storeMutations
...storeMutations,
...managerMutations
},
Query: {
...userQueries,
...itemQueries,
...orderQueries,
...storeQueries
...storeQueries,
...managerQueries
}
};

Expand Down
6 changes: 4 additions & 2 deletions api/src/types/Item.ts
Expand Up @@ -6,17 +6,19 @@ const ItemType = `
store: Store! @embedded
unit: ItemUnit @column
pricePerUnit: Int! @column
featured: Boolean! @column
}
enum ItemUnit {
Kilograms
Litres
Kilogram
Litre
}
input ItemInput {
name: String!
pricePerUnit: Int!
unit: ItemUnit
featured: Boolean
}
extend type Mutation {
Expand Down
7 changes: 7 additions & 0 deletions api/src/types/Store.ts
@@ -1,10 +1,17 @@
const StoreType = `
type Store @entity {
_id: ID! @id
name: String! @column
websiteUrl: String @column
instagramUsername: String @column
twitterUsername: String @column
}
input StoreInput {
name: String
websiteUrl: String
instagramUsername: String
twitterUsername: String
}
extend type Query {
Expand Down
1 change: 1 addition & 0 deletions dashboard/.eslintrc
@@ -0,0 +1 @@
{ "extends": "../.eslintrc" }
2 changes: 1 addition & 1 deletion dashboard/codegen.yml
@@ -1,6 +1,6 @@
overwrite: true
schema: http://localhost:5000
documents: src/**/*.graphql
documents: graphql/*.graphql
generates:
src/types.tsx:
plugins:
Expand Down
29 changes: 29 additions & 0 deletions dashboard/graphql/Item.graphql
@@ -0,0 +1,29 @@
mutation CreateItem($storeId: ID!, $input: ItemInput!) {
createItem(storeId: $storeId, input: $input) {
_id
name
pricePerUnit
featured
unit
}
}

query StoreItems($storeId: ID!) {
storeItems(storeId: $storeId) {
_id
name
pricePerUnit
featured
unit
}
}

query Items {
items {
_id
name
pricePerUnit
featured
unit
}
}
17 changes: 17 additions & 0 deletions dashboard/graphql/Manager.graphql
@@ -0,0 +1,17 @@
mutation CreateManager($storeId: ID!, $input: ManagerInput) {
createManager(storeId: $storeId, input: $input) {
_id
name
email
role
}
}

query StoreManagers($storeId: ID!) {
storeManagers(storeId: $storeId) {
_id
name
email
role
}
}
6 changes: 6 additions & 0 deletions dashboard/graphql/Store.graphql
@@ -0,0 +1,6 @@
mutation CreateStore($input: StoreInput) {
createStore(input: $input) {
_id
name
}
}
2 changes: 2 additions & 0 deletions dashboard/package.json
Expand Up @@ -11,11 +11,13 @@
"@types/react": "^16.9.0",
"@types/react-dom": "^16.9.0",
"formik": "^2.1.4",
"graphql": "^15.0.0",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-router-dom": "^5.1.2",
"react-scripts": "3.4.1",
"react-select": "^3.1.0",
"react-spring": "^8.0.27",
"styled-components": "^5.0.1",
"typescript": "~3.7.2",
"urql": "^1.9.5"
Expand Down
26 changes: 0 additions & 26 deletions dashboard/src/App.js

This file was deleted.

9 changes: 0 additions & 9 deletions dashboard/src/App.test.js

This file was deleted.

45 changes: 45 additions & 0 deletions dashboard/src/App.tsx
@@ -0,0 +1,45 @@
import React from 'react';
import styled from 'styled-components';
import { BrowserRouter, Switch, Route } from 'react-router-dom';

import Home from './pages/Home';
import Orders from './pages/Orders';
import Items from './pages/Items';

import Sidebar from './components/Sidebar';
import { Provider, createClient } from 'urql';

const AppContainer = styled.div`
display: flex;
align-items: stretch;
height: 100vh;
`;

const MainContainer = styled.main`
flex-grow: 1;
`;

const client = createClient({
url: 'http://localhost:5000'
});

const App = () => {
return (
<Provider value={client}>
<BrowserRouter>
<AppContainer>
<Sidebar />
<MainContainer>
<Switch>
<Route exact path='/' component={Home} />
<Route exact path='/orders' component={Orders} />
<Route exact path='/items' component={Items} />
</Switch>
</MainContainer>
</AppContainer>
</BrowserRouter>
</Provider>
);
};

export default App;
8 changes: 4 additions & 4 deletions dashboard/src/index.js → dashboard/src/index.tsx
Expand Up @@ -5,10 +5,10 @@ import App from './App';
import * as serviceWorker from './serviceWorker';

ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
);

// If you want your app to work offline and load faster, you can change
Expand Down
27 changes: 27 additions & 0 deletions dashboard/src/pages/Onboarding.tsx
@@ -0,0 +1,27 @@
import React from 'react';
import styled from 'styled-components';

const PageBackground = styled.main`
display: flex;
justify-content: center;
align-items: center;
height: 100%;
width: 100%;
background-color: #efefef;
`;

const OnboardingContainer = styled.div`
border-radius: 6px;
box-shadow: 0 1px 3px hsla(0, 0%, 0.2);
padding: 20px;
`;

const Onboarding = () => {
return (
<PageBackground>
<OnboardingContainer>Onboarding</OnboardingContainer>
</PageBackground>
);
};

export default Onboarding;
1 change: 1 addition & 0 deletions dashboard/src/react-app-env.d.ts
@@ -0,0 +1 @@
/// <reference types="react-scripts" />

0 comments on commit be5b74c

Please sign in to comment.