Dwayne Harris 4 years ago
parent
commit
46d65c6f57
  1. 16
      src/actions/apps.ts
  2. 6
      src/actions/authentication.ts
  3. 4
      src/actions/composer.ts
  4. 20
      src/actions/groups.ts
  5. 8
      src/actions/posts.ts
  6. 8
      src/actions/registration.ts
  7. 6
      src/actions/users.ts
  8. 2
      src/api/fetch.ts
  9. 11
      src/components/controls/file-field.tsx
  10. 6
      src/components/group-invitations.tsx
  11. 2
      src/types/index.ts

16
src/actions/apps.ts

@ -19,7 +19,7 @@ export const fetchApps = (sort?: string, continuation?: string): AppThunkAction
try {
const response = await apiFetch<AppsResponse>({
path: `/api/apps?${objectToQuerystring({ sort, continuation })}`,
path: `/v1/apps?${objectToQuerystring({ sort, continuation })}`,
})
const apps = normalize(response.apps, EntityType.App)
@ -44,7 +44,7 @@ export const fetchCreatedApps = (sort?: string): AppThunkAction => async dispatc
try {
const response = await apiFetch<AppsResponse>({
path: `/api/self/apps?${objectToQuerystring({ sort })}`,
path: `/v1/self/apps?${objectToQuerystring({ sort })}`,
})
const apps = normalize(response.apps, EntityType.App)
@ -63,7 +63,7 @@ export const checkAppAvailability = (name: string): AppThunkAction => async disp
try {
const { id, available } = await apiFetch<AvailabilityResponse>({
path: '/api/app/available',
path: '/v1/app/available',
method: 'post',
body: {
name,
@ -106,7 +106,7 @@ export const createApp = (options: AppOptions): AppThunkAction<string> => async
try {
const { id } = await apiFetch<CreateAppResponse>({
path: '/api/app',
path: '/v1/app',
method: 'post',
body: {
name,
@ -136,7 +136,7 @@ export const updateApp = (id: string, options: AppOptions): AppThunkAction => as
try {
await apiFetch({
path: `/api/app/${id}`,
path: `/v1/app/${id}`,
method: 'put',
body: {
name,
@ -164,7 +164,7 @@ export const fetchApp = (id: string): AppThunkAction => async dispatch => {
try {
const app = await apiFetch<App>({
path: `/api/app/${id}`,
path: `/v1/app/${id}`,
method: 'get',
})
@ -182,7 +182,7 @@ export const installApp = (id: string): AppThunkAction => async dispatch => {
try {
await apiFetch({
path: `/api/app/${id}/install`,
path: `/v1/app/${id}/install`,
method: 'post'
})
@ -198,7 +198,7 @@ export const uninstallApp = (id: string): AppThunkAction => async dispatch => {
try {
await apiFetch({
path: `/api/app/${id}/uninstall`,
path: `/v1/app/${id}/uninstall`,
method: 'post'
})

6
src/actions/authentication.ts

@ -56,7 +56,7 @@ export const fetchSelf = (): AppThunkAction => async dispatch => {
try {
const self = await apiFetch<Entity>({
path: '/api/self',
path: '/v1/self',
})
const result = normalize([self], EntityType.User)
@ -85,7 +85,7 @@ export const authenticate = (name: string, password: string): AppThunkAction<str
try {
const response = await apiFetch<AuthenticateResponse>({
path: '/api/authenticate',
path: '/v1/authenticate',
method: 'post',
body: {
id: name,
@ -124,7 +124,7 @@ export const updateSelf = (options: UpdateSelfOptions): AppThunkAction => async
try {
const self = await apiFetch<Entity>({
path: '/api/self',
path: '/v1/self',
method: 'put',
body: {
name,

4
src/actions/composer.ts

@ -57,7 +57,7 @@ export const fetchInstallations = (): AppThunkAction => async dispatch => {
try {
const response = await apiFetch<FetchInstallationsResponse>({
path: '/api/installations',
path: '/v1/installations',
})
const result = normalize(response.installations, EntityType.Installation)
@ -76,7 +76,7 @@ export const saveInstallationSettings = (id: string, settings: Settings): AppThu
try {
await apiFetch({
path: `/api/installation/${id}/settings`,
path: `/v1/installation/${id}/settings`,
method: 'put',
body: { settings },
})

20
src/actions/groups.ts

@ -15,7 +15,7 @@ export const fetchGroup = (id: string): AppThunkAction => {
try {
const group = await apiFetch<Entity>({
path: `/api/group/${id}`
path: `/v1/group/${id}`
})
const groups = normalize([group], EntityType.Group)
@ -39,7 +39,7 @@ export const fetchGroups = (sort?: string, continuation?: string): AppThunkActio
try {
const response = await apiFetch<GroupsResponse>({
path: `/api/groups?${objectToQuerystring({ sort, continuation })}`,
path: `/v1/groups?${objectToQuerystring({ sort, continuation })}`,
})
const groups = normalize(response.groups, EntityType.Group)
@ -69,7 +69,7 @@ export const fetchGroupMembers = (id: string, type?: string, continuation?: stri
try {
const response = await apiFetch<GroupMembersResponse>({
path: `/api/group/${id}/members?${objectToQuerystring({ type, continuation })}`,
path: `/v1/group/${id}/members?${objectToQuerystring({ type, continuation })}`,
})
const users = normalize(response.members, EntityType.User)
@ -94,12 +94,12 @@ interface GroupLogsResponse {
continuation?: string
}
export const fetchLogs = (id: string, continuation?: string): AppThunkAction => async dispatch => {
export const fetchLogs = (continuation?: string): AppThunkAction => async dispatch => {
dispatch(startRequest(RequestKey.FetchGroupLogs))
try {
const response = await apiFetch<GroupLogsResponse>({
path: `/api/group/${id}/logs?${objectToQuerystring({ continuation })}`,
path: `/v1/group/logs?${objectToQuerystring({ continuation })}`,
})
const logs = normalize(response.logs, EntityType.Log)
@ -123,12 +123,12 @@ interface CreateInvitationResponse {
code: string
}
export const createInvitation = (id: string, expiration?: number, limit?: number): AppThunkAction<string> => async dispatch => {
export const createInvitation = (expiration?: number, limit?: number): AppThunkAction<string> => async dispatch => {
dispatch(startRequest(RequestKey.CreateInvitation))
try {
const response = await apiFetch<CreateInvitationResponse>({
path: `/api/group/${id}/invitation`,
path: `/v1/group/invitation`,
method: 'post',
body: {
expiration,
@ -149,12 +149,12 @@ interface InvitationsResponse {
continuation?: string
}
export const fetchInvitations = (id: string): AppThunkAction => async dispatch => {
export const fetchInvitations = (): AppThunkAction => async dispatch => {
dispatch(startRequest(RequestKey.FetchInvitations))
try {
const response = await apiFetch<InvitationsResponse>({
path: `/api/group/${id}/invitations`,
path: `/v1/group/invitations`,
})
const invitations = normalize(response.invitations, EntityType.Invitation)
@ -173,7 +173,7 @@ export const updateGroup = (id: string, updates: object): AppThunkAction => asyn
try {
await apiFetch({
path: `/api/group/${id}`,
path: `/v1/group/${id}`,
method: 'put',
body: updates,
})

8
src/actions/posts.ts

@ -30,7 +30,7 @@ export const createPost = (options: CreatePostOptions): AppThunkAction<string> =
try {
const post = await apiFetch<CreatePostResponse>({
path: `/api/post`,
path: `/v1/post`,
method: 'post',
body: {
installation,
@ -65,7 +65,7 @@ export const fetchPost = (id: string): AppThunkAction => {
try {
const response = await apiFetch<FetchPostResponse>({
path: `/api/post/${id}`
path: `/v1/post/${id}`
})
const parents = normalize(response.parents.map(p => ({
@ -113,7 +113,7 @@ export const fetchTimeline = (continuation?: string): AppThunkAction => async di
try {
const response = await apiFetch<TimelineResponse>({
path: `/api/timeline?${objectToQuerystring({ continuation })}`,
path: `/v1/timeline?${objectToQuerystring({ continuation })}`,
})
const posts = normalize(response.posts, EntityType.Post)
@ -144,7 +144,7 @@ export const fetchUserPosts = (id: string, continuation?: string): AppThunkActio
try {
const response = await apiFetch<UserPostsResponse>({
path: `/api/user/${id}/posts`,
path: `/v1/user/${id}/posts`,
})
const posts = normalize(response.posts.map(p => ({

8
src/actions/registration.ts

@ -28,7 +28,7 @@ export const checkGroupAvailability = (name: string): AppThunkAction => async di
try {
const { id, available } = await apiFetch<AvailabilityResponse>({
path: '/api/group/available',
path: '/v1/group/available',
method: 'post',
body: {
name,
@ -53,7 +53,7 @@ export const checkUserAvailability = (name: string): AppThunkAction => async dis
try {
const { id, available } = await apiFetch<AvailabilityResponse>({
path: '/api/user/available',
path: '/v1/user/available',
method: 'post',
body: {
name,
@ -94,7 +94,7 @@ export const createGroup = (options: CreateGroupOptions): AppThunkAction<string>
try {
const { id } = await apiFetch<CreateGroupResponse>({
path: '/api/group',
path: '/v1/group',
method: 'post',
body: {
name,
@ -142,7 +142,7 @@ export const register = (options: RegisterOptions): AppThunkAction<string> => as
try {
const response = await apiFetch<RegisterResponse>({
path: '/api/register',
path: '/v1/register',
method: 'post',
body: {
id,

6
src/actions/users.ts

@ -10,7 +10,7 @@ export const fetchUser = (id: string): AppThunkAction => {
try {
const user = await apiFetch<Entity>({
path: `/api/user/${id}`
path: `/v1/user/${id}`
})
const users = normalize([user], EntityType.User)
@ -30,7 +30,7 @@ export const subscribe = (id: string): AppThunkAction => {
try {
await apiFetch<Entity>({
path: `/api/user/${id}/subscribe`,
path: `/v1/user/${id}/subscribe`,
method: 'post',
})
@ -48,7 +48,7 @@ export const unsubscribe = (id: string): AppThunkAction => {
try {
await apiFetch<Entity>({
path: `/api/user/${id}/unsubscribe`,
path: `/v1/user/${id}/unsubscribe`,
method: 'post',
})

2
src/api/fetch.ts

@ -96,7 +96,7 @@ export const apiFetch: APIFetch = async (options: FetchOptions) => {
const refreshToken = localStorage.getItem(LOCAL_STORAGE_REFRESH_TOKEN_KEY)
if (accessToken && refreshToken) {
const refreshResponse = await fetch(`${config.apiUrl}/api/refresh`, {
const refreshResponse = await fetch(`${config.apiUrl}/v1/refresh`, {
headers: new Headers({
'Content-Type': contentType,
'Authorization': `Bearer ${accessToken}`

11
src/components/controls/file-field.tsx

@ -45,7 +45,7 @@ const FileField: FC<Props> = props => {
}
const ext = file.name.substring(file.name.lastIndexOf('.'))
const { sas, id } = await apiFetch<SasResponse>({ path: '/api/sas' })
const { sas, id } = await apiFetch<SasResponse>({ path: '/v1/sas' })
const filename = `${id}${ext}`
setUploading(true)
@ -59,7 +59,7 @@ const FileField: FC<Props> = props => {
})
await apiFetch({
path: '/api/media',
path: '/v1/media',
method: 'post',
body: {
name: filename,
@ -83,11 +83,8 @@ const FileField: FC<Props> = props => {
const handleDelete = async () => {
if (uploaded) {
await apiFetch({
path: '/api/media/delete',
method: 'post',
body: {
name: value,
}
path: `/v1/media?name=${value}`,
method: 'delete',
})
}

6
src/components/group-invitations.tsx

@ -31,8 +31,8 @@ const GroupInvitations: FC<Props> = ({ group }) => {
const handleCreateInvitation = async () => {
try {
await dispatch(createInvitation(group, moment().add(expiration, 'day').valueOf(), parseInt(limit, 10)))
await dispatch(fetchInvitations(group))
await dispatch(createInvitation(moment().add(expiration, 'day').valueOf(), parseInt(limit, 10)))
await dispatch(fetchInvitations())
} catch (err) {
handleApiError(err, dispatch, history)
}
@ -41,7 +41,7 @@ const GroupInvitations: FC<Props> = ({ group }) => {
useEffect(() => {
if (invitations.length === 0) {
try {
dispatch(fetchInvitations(group))
dispatch(fetchInvitations())
} catch (err) {
handleApiError(err, dispatch, history)
}

2
src/types/index.ts

@ -2,7 +2,7 @@ import { AnyAction } from 'redux'
import { ThunkDispatch, ThunkAction } from 'redux-thunk'
import { AppState } from './store'
export type FetchMethods = 'get' | 'post' | 'put'
export type FetchMethods = 'get' | 'post' | 'put' | 'delete'
export interface FetchOptions {
path: string

Loading…
Cancel
Save