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

6
src/actions/authentication.ts

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

4
src/actions/composer.ts

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

20
src/actions/groups.ts

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

8
src/actions/posts.ts

@ -30,7 +30,7 @@ export const createPost = (options: CreatePostOptions): AppThunkAction<string> =
try { try {
const post = await apiFetch<CreatePostResponse>({ const post = await apiFetch<CreatePostResponse>({
path: `/api/post`,
path: `/v1/post`,
method: 'post', method: 'post',
body: { body: {
installation, installation,
@ -65,7 +65,7 @@ export const fetchPost = (id: string): AppThunkAction => {
try { try {
const response = await apiFetch<FetchPostResponse>({ const response = await apiFetch<FetchPostResponse>({
path: `/api/post/${id}`
path: `/v1/post/${id}`
}) })
const parents = normalize(response.parents.map(p => ({ const parents = normalize(response.parents.map(p => ({
@ -113,7 +113,7 @@ export const fetchTimeline = (continuation?: string): AppThunkAction => async di
try { try {
const response = await apiFetch<TimelineResponse>({ const response = await apiFetch<TimelineResponse>({
path: `/api/timeline?${objectToQuerystring({ continuation })}`,
path: `/v1/timeline?${objectToQuerystring({ continuation })}`,
}) })
const posts = normalize(response.posts, EntityType.Post) const posts = normalize(response.posts, EntityType.Post)
@ -144,7 +144,7 @@ export const fetchUserPosts = (id: string, continuation?: string): AppThunkActio
try { try {
const response = await apiFetch<UserPostsResponse>({ const response = await apiFetch<UserPostsResponse>({
path: `/api/user/${id}/posts`,
path: `/v1/user/${id}/posts`,
}) })
const posts = normalize(response.posts.map(p => ({ 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 { try {
const { id, available } = await apiFetch<AvailabilityResponse>({ const { id, available } = await apiFetch<AvailabilityResponse>({
path: '/api/group/available',
path: '/v1/group/available',
method: 'post', method: 'post',
body: { body: {
name, name,
@ -53,7 +53,7 @@ export const checkUserAvailability = (name: string): AppThunkAction => async dis
try { try {
const { id, available } = await apiFetch<AvailabilityResponse>({ const { id, available } = await apiFetch<AvailabilityResponse>({
path: '/api/user/available',
path: '/v1/user/available',
method: 'post', method: 'post',
body: { body: {
name, name,
@ -94,7 +94,7 @@ export const createGroup = (options: CreateGroupOptions): AppThunkAction<string>
try { try {
const { id } = await apiFetch<CreateGroupResponse>({ const { id } = await apiFetch<CreateGroupResponse>({
path: '/api/group',
path: '/v1/group',
method: 'post', method: 'post',
body: { body: {
name, name,
@ -142,7 +142,7 @@ export const register = (options: RegisterOptions): AppThunkAction<string> => as
try { try {
const response = await apiFetch<RegisterResponse>({ const response = await apiFetch<RegisterResponse>({
path: '/api/register',
path: '/v1/register',
method: 'post', method: 'post',
body: { body: {
id, id,

6
src/actions/users.ts

@ -10,7 +10,7 @@ export const fetchUser = (id: string): AppThunkAction => {
try { try {
const user = await apiFetch<Entity>({ const user = await apiFetch<Entity>({
path: `/api/user/${id}`
path: `/v1/user/${id}`
}) })
const users = normalize([user], EntityType.User) const users = normalize([user], EntityType.User)
@ -30,7 +30,7 @@ export const subscribe = (id: string): AppThunkAction => {
try { try {
await apiFetch<Entity>({ await apiFetch<Entity>({
path: `/api/user/${id}/subscribe`,
path: `/v1/user/${id}/subscribe`,
method: 'post', method: 'post',
}) })
@ -48,7 +48,7 @@ export const unsubscribe = (id: string): AppThunkAction => {
try { try {
await apiFetch<Entity>({ await apiFetch<Entity>({
path: `/api/user/${id}/unsubscribe`,
path: `/v1/user/${id}/unsubscribe`,
method: 'post', 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) const refreshToken = localStorage.getItem(LOCAL_STORAGE_REFRESH_TOKEN_KEY)
if (accessToken && refreshToken) { if (accessToken && refreshToken) {
const refreshResponse = await fetch(`${config.apiUrl}/api/refresh`, {
const refreshResponse = await fetch(`${config.apiUrl}/v1/refresh`, {
headers: new Headers({ headers: new Headers({
'Content-Type': contentType, 'Content-Type': contentType,
'Authorization': `Bearer ${accessToken}` '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 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}` const filename = `${id}${ext}`
setUploading(true) setUploading(true)
@ -59,7 +59,7 @@ const FileField: FC<Props> = props => {
}) })
await apiFetch({ await apiFetch({
path: '/api/media',
path: '/v1/media',
method: 'post', method: 'post',
body: { body: {
name: filename, name: filename,
@ -83,11 +83,8 @@ const FileField: FC<Props> = props => {
const handleDelete = async () => { const handleDelete = async () => {
if (uploaded) { if (uploaded) {
await apiFetch({ 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 () => { const handleCreateInvitation = async () => {
try { 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) { } catch (err) {
handleApiError(err, dispatch, history) handleApiError(err, dispatch, history)
} }
@ -41,7 +41,7 @@ const GroupInvitations: FC<Props> = ({ group }) => {
useEffect(() => { useEffect(() => {
if (invitations.length === 0) { if (invitations.length === 0) {
try { try {
dispatch(fetchInvitations(group))
dispatch(fetchInvitations())
} catch (err) { } catch (err) {
handleApiError(err, dispatch, history) handleApiError(err, dispatch, history)
} }

2
src/types/index.ts

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

Loading…
Cancel
Save