Dwayne Harris
5 years ago
23 changed files with 323 additions and 216 deletions
-
30src/actions/authentication.ts
-
45src/actions/directory.ts
-
129src/actions/registration.ts
-
6src/api/errors.ts
-
6src/api/fetch.ts
-
42src/api/groups.ts
-
1src/api/index.ts
-
46src/api/registration.ts
-
0src/api/users.ts
-
2src/components/app/app.scss
-
17src/components/app/app.tsx
-
13src/components/app/index.ts
-
2src/components/create-group-form/index.ts
-
2src/components/forms/password-field/password-field.tsx
-
21src/components/forms/select-field/select-field.tsx
-
7src/components/forms/text-field/text-field.tsx
-
27src/components/pages/register/index.ts
-
23src/components/pages/self/index.ts
-
30src/components/pages/self/self.tsx
-
7src/constants/index.ts
-
1src/selectors/authentication.ts
-
2src/types/index.ts
-
2src/utils/index.ts
@ -1,42 +0,0 @@ |
|||
import { fetch } from './fetch' |
|||
import { Entity } from '../types' |
|||
|
|||
interface GroupsResponse { |
|||
groups: Entity[] |
|||
continuation?: string |
|||
} |
|||
|
|||
interface NewGroupResponse { |
|||
id: string |
|||
} |
|||
|
|||
export async function getGroup(id: string) { |
|||
return await fetch<Entity>({ |
|||
path: `/api/group/${id}` |
|||
}) |
|||
} |
|||
|
|||
export async function getGroups(sort: string = 'members', continuation?: string) { |
|||
const params = { |
|||
sort, |
|||
continuation, |
|||
} |
|||
|
|||
const querystring = Object.entries(params).filter(([name, value]) => value !== undefined).map(([name, value]) => `${name}=${value}`).join('&') |
|||
|
|||
return await fetch<GroupsResponse>({ |
|||
path: `/api/groups?${querystring}` |
|||
}) |
|||
} |
|||
|
|||
export async function createGroup(name: string, registration: string, about?: string) { |
|||
return await fetch<NewGroupResponse>({ |
|||
path: '/api/group', |
|||
method: 'post', |
|||
body: { |
|||
name, |
|||
registration, |
|||
about, |
|||
}, |
|||
}) |
|||
} |
@ -0,0 +1 @@ |
|||
export { apiFetch } from './fetch' |
@ -1,46 +0,0 @@ |
|||
import { fetch } from './fetch' |
|||
|
|||
interface AvailabilityResponse { |
|||
id: string |
|||
available: boolean |
|||
} |
|||
|
|||
interface RegisterResponse { |
|||
id: string |
|||
access: string |
|||
refresh: string |
|||
} |
|||
|
|||
export async function fetchGroupAvailability(name: string) { |
|||
return await fetch<AvailabilityResponse>({ |
|||
path: '/api/group/available', |
|||
method: 'post', |
|||
body: { |
|||
name, |
|||
}, |
|||
}) |
|||
} |
|||
|
|||
export async function fetchUserAvailability(name: string) { |
|||
return await fetch<AvailabilityResponse>({ |
|||
path: '/api/user/available', |
|||
method: 'post', |
|||
body: { |
|||
name, |
|||
}, |
|||
}) |
|||
} |
|||
|
|||
export async function register(id: string, email: string, password: string, name?: string, group?: string) { |
|||
return await fetch<RegisterResponse>({ |
|||
path: '/api/register', |
|||
method: 'post', |
|||
body: { |
|||
id, |
|||
email, |
|||
password, |
|||
name, |
|||
group, |
|||
}, |
|||
}) |
|||
} |
@ -0,0 +1,23 @@ |
|||
|
|||
import { connect } from 'react-redux' |
|||
import { getAuthenticatedUserId } from 'src/selectors/authentication' |
|||
import { getEntity } from 'src/selectors/entities' |
|||
import { AppState, AppThunkDispatch } from 'src/types' |
|||
|
|||
import Self from './self' |
|||
|
|||
const mapStateToProps = (state: AppState) => { |
|||
const userId = getAuthenticatedUserId(state) |
|||
const user = userId ? getEntity(state, 'user', userId) : undefined |
|||
|
|||
return { |
|||
user, |
|||
} |
|||
} |
|||
|
|||
const mapDispatchToProps = (dispatch: AppThunkDispatch) => ({}) |
|||
|
|||
export default connect( |
|||
mapStateToProps, |
|||
mapDispatchToProps |
|||
)(Self) |
@ -0,0 +1,30 @@ |
|||
import React, { FC, useEffect } from 'react' |
|||
import { setTitle } from 'src/utils' |
|||
|
|||
import { Entity } from 'src/types' |
|||
|
|||
import PageHeader from 'src/components/page-header' |
|||
|
|||
interface Props { |
|||
user?: Entity |
|||
} |
|||
|
|||
const Self: FC<Props> = ({ user }) => { |
|||
useEffect(() => { |
|||
if (user) setTitle(user.name as string) |
|||
}, [user]) |
|||
|
|||
return ( |
|||
<div> |
|||
<PageHeader title={user ? user.name as string : '?'} /> |
|||
|
|||
<div className="main-content"> |
|||
<p> |
|||
Hello. |
|||
</p> |
|||
</div> |
|||
</div> |
|||
) |
|||
} |
|||
|
|||
export default Self |
@ -1,3 +1,4 @@ |
|||
import { AppState } from '../types' |
|||
|
|||
export const getAuthenticated = (state: AppState) => state.authentication.authenticated |
|||
export const getAuthenticatedUserId = (state: AppState) => state.authentication.userId |
Write
Preview
Loading…
Cancel
Save
Reference in new issue