Dwayne Harris
5 years ago
24 changed files with 223 additions and 66 deletions
-
13src/actions/registration.ts
-
1src/components/app/app.scss
-
5src/components/app/index.ts
-
30src/components/create-group-form/create-group-form.tsx
-
21src/components/create-group-form/index.ts
-
4src/components/create-user-form/create-user-form.tsx
-
7src/components/create-user-form/index.ts
-
4src/components/pages/directory/index.ts
-
2src/components/pages/register-group/index.ts
-
13src/components/pages/register/index.ts
-
72src/components/pages/register/register.tsx
-
2src/components/text-field/index.ts
-
2src/components/user-info/index.ts
-
22src/reducers/registration.ts
-
3src/selectors/authentication.ts
-
15src/selectors/directory.ts
-
10src/selectors/entities.ts
-
13src/selectors/forms.ts
-
36src/selectors/index.ts
-
3src/selectors/menu.ts
-
3src/selectors/registration.ts
-
2src/store/index.ts
-
1src/types/index.ts
-
5src/types/store.ts
@ -0,0 +1,13 @@ |
|||
import { Action } from 'redux' |
|||
|
|||
export interface SetPageAction extends Action { |
|||
type: 'REGISTRATION_SET_PAGE' |
|||
payload: number |
|||
} |
|||
|
|||
export type RegistrationActions = SetPageAction |
|||
|
|||
export const setPage = (page: number): SetPageAction => ({ |
|||
type: 'REGISTRATION_SET_PAGE', |
|||
payload: page, |
|||
}) |
@ -0,0 +1,30 @@ |
|||
import React, { FC, useEffect } from 'react' |
|||
import TextField from '../text-field' |
|||
|
|||
interface Props { |
|||
initForm: () => void |
|||
} |
|||
|
|||
const CreateGroupForm: FC<Props> = ({ initForm }) => { |
|||
useEffect(() => { |
|||
initForm() |
|||
}, []) |
|||
|
|||
return ( |
|||
<div className="container"> |
|||
<TextField name="name" label="Community Name" /> |
|||
|
|||
<div className="field"> |
|||
<label className="label">Registration Type</label> |
|||
<div className="select is-small"> |
|||
<select> |
|||
<option>Anyone can join</option> |
|||
<option>Invite only</option> |
|||
</select> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
) |
|||
} |
|||
|
|||
export default CreateGroupForm |
@ -0,0 +1,21 @@ |
|||
import { Dispatch } from 'redux' |
|||
import { connect } from 'react-redux' |
|||
|
|||
import { initField } from 'src/actions/forms' |
|||
import { AppState } from 'src/types' |
|||
|
|||
import CreateGroupForm from './create-group-form' |
|||
|
|||
const mapStateToProps = (state: AppState) => ({ |
|||
}) |
|||
|
|||
const mapDispatchToProps = (dispatch: Dispatch) => ({ |
|||
initForm: () => { |
|||
dispatch(initField('name')) |
|||
} |
|||
}) |
|||
|
|||
export default connect( |
|||
mapStateToProps, |
|||
mapDispatchToProps |
|||
)(CreateGroupForm) |
@ -0,0 +1,22 @@ |
|||
import { Reducer } from 'redux' |
|||
|
|||
import { RegistrationActions } from '../actions/registration' |
|||
import { RegistrationState } from '../types' |
|||
|
|||
const initialState: RegistrationState = { |
|||
page: 0, |
|||
} |
|||
|
|||
const reducer: Reducer<RegistrationState, RegistrationActions> = (state = initialState, action) => { |
|||
switch (action.type) { |
|||
case 'REGISTRATION_SET_PAGE': |
|||
return { |
|||
...state, |
|||
page: action.payload, |
|||
} |
|||
default: |
|||
return state |
|||
} |
|||
} |
|||
|
|||
export default reducer |
@ -0,0 +1,3 @@ |
|||
import { AppState } from '../types' |
|||
|
|||
export const getAuthenticated = (state: AppState) => state.authentication.authenticated |
@ -0,0 +1,15 @@ |
|||
import { denormalize } from 'normalizr' |
|||
import { createSelector } from 'reselect' |
|||
|
|||
import { groupSchema } from '../store/schemas' |
|||
import { getEntityStore } from './entities' |
|||
import { AppState, Entity } from '../types' |
|||
|
|||
export const getGroupIds = (state: AppState) => state.directory.groups |
|||
|
|||
export const getGroups = createSelector( |
|||
[getEntityStore, getGroupIds], |
|||
(store, groups) => { |
|||
return denormalize(groups, [groupSchema], store) as Entity[] |
|||
} |
|||
) |
@ -0,0 +1,10 @@ |
|||
import { AppState } from '../types' |
|||
|
|||
export const getEntityStore = (state: AppState) => state.entities |
|||
|
|||
export const getEntity = (state: AppState, type: string, id: string) => { |
|||
const store = getEntityStore(state) |
|||
const collection = store[type] |
|||
|
|||
return collection ? collection[id] : undefined |
|||
} |
@ -0,0 +1,13 @@ |
|||
import { AppState } from '../types' |
|||
|
|||
export const getForm = (state: AppState) => state.forms.form |
|||
|
|||
export const getFieldValue = (state: AppState, name: string) => { |
|||
const field = getForm(state)[name] |
|||
return field ? field.value : undefined |
|||
} |
|||
|
|||
export const getFieldNotification = (state: AppState, name: string) => { |
|||
const field = getForm(state)[name] |
|||
return field ? field.notification : undefined |
|||
} |
@ -1,45 +1,11 @@ |
|||
import { denormalize } from 'normalizr' |
|||
import { createSelector } from 'reselect' |
|||
import values from 'lodash/values' |
|||
|
|||
import { groupSchema } from '../store/schemas' |
|||
import { AppState, Entity } from '../types' |
|||
import { AppState } from '../types' |
|||
|
|||
export const getEntityStore = (state: AppState) => state.entities |
|||
|
|||
export const getEntity = (state: AppState, type: string, id: string) => { |
|||
const store = getEntityStore(state) |
|||
const collection = store[type] |
|||
|
|||
return collection ? collection[id] : undefined |
|||
} |
|||
|
|||
export const getForm = (state: AppState) => state.forms.form |
|||
|
|||
export const getFieldValue = (state: AppState, name: string) => { |
|||
const field = getForm(state)[name] |
|||
return field ? field.value : undefined |
|||
} |
|||
|
|||
export const getFieldNotification = (state: AppState, name: string) => { |
|||
const field = getForm(state)[name] |
|||
return field ? field.notification : undefined |
|||
} |
|||
|
|||
export const getMenuCollapsed = (state: AppState) => state.menu.collapsed |
|||
export const getAuthenticated = (state: AppState) => state.authentication.authenticated |
|||
export const getNotifications = (state: AppState) => state.notifications |
|||
export const getRequests = (state: AppState) => state.requests |
|||
|
|||
export const getFetching = createSelector(getRequests, requests => { |
|||
return values(requests).reduce((fetching, request) => fetching || request.fetching, false) |
|||
}) |
|||
|
|||
export const getDirectoryGroupIds = (state: AppState) => state.directory.groups |
|||
|
|||
export const getDirectoryGroups = createSelector( |
|||
[getEntityStore, getDirectoryGroupIds], |
|||
(store, groups) => { |
|||
return denormalize(groups, [groupSchema], store) as Entity[] |
|||
} |
|||
) |
@ -0,0 +1,3 @@ |
|||
import { AppState } from '../types' |
|||
|
|||
export const getCollapsed = (state: AppState) => state.menu.collapsed |
@ -0,0 +1,3 @@ |
|||
import { AppState } from 'src/types' |
|||
|
|||
export const getPage = (state: AppState) => state.registration.page |
Write
Preview
Loading…
Cancel
Save
Reference in new issue