mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 12:56:41 +07:00
removed redux completely
This commit is contained in:
parent
26e6d8d41b
commit
a4bb07e9cf
323 changed files with 2464 additions and 3348 deletions
71
src/api/auth/index.ts
Normal file
71
src/api/auth/index.ts
Normal file
|
@ -0,0 +1,71 @@
|
|||
import { api, cleanResult } from '~/utils/api';
|
||||
import { API } from '~/constants/api';
|
||||
import {
|
||||
ApiAttachSocialRequest,
|
||||
ApiAttachSocialResult,
|
||||
ApiAuthGetUpdatesRequest,
|
||||
ApiAuthGetUpdatesResult,
|
||||
ApiAuthGetUserProfileRequest,
|
||||
ApiAuthGetUserProfileResult,
|
||||
ApiAuthGetUserResult,
|
||||
ApiCheckRestoreCodeRequest,
|
||||
ApiCheckRestoreCodeResult,
|
||||
ApiDropSocialRequest,
|
||||
ApiDropSocialResult,
|
||||
ApiGetSocialsResult,
|
||||
ApiLoginWithSocialRequest,
|
||||
ApiLoginWithSocialResult,
|
||||
ApiRestoreCodeRequest,
|
||||
ApiRestoreCodeResult,
|
||||
ApiUpdateUserRequest,
|
||||
ApiUpdateUserResult,
|
||||
ApiUserLoginRequest,
|
||||
ApiUserLoginResult,
|
||||
} from '~/api/auth/types';
|
||||
|
||||
export const apiUserLogin = ({ username, password }: ApiUserLoginRequest) =>
|
||||
api
|
||||
.post<ApiUserLoginResult>(API.USER.LOGIN, { username, password })
|
||||
.then(cleanResult);
|
||||
|
||||
export const apiAuthGetUser = () => api.get<ApiAuthGetUserResult>(API.USER.ME).then(cleanResult);
|
||||
|
||||
export const apiAuthGetUserProfile = ({ username }: ApiAuthGetUserProfileRequest) =>
|
||||
api.get<ApiAuthGetUserProfileResult>(API.USER.PROFILE(username)).then(cleanResult);
|
||||
|
||||
export const apiAuthGetUpdates = ({ exclude_dialogs, last }: ApiAuthGetUpdatesRequest) =>
|
||||
api
|
||||
.get<ApiAuthGetUpdatesResult>(API.USER.GET_UPDATES, { params: { exclude_dialogs, last } })
|
||||
.then(cleanResult);
|
||||
|
||||
export const apiUpdateUser = ({ user }: ApiUpdateUserRequest) =>
|
||||
api.patch<ApiUpdateUserResult>(API.USER.ME, user).then(cleanResult);
|
||||
|
||||
export const apiRequestRestoreCode = (field: string) =>
|
||||
api
|
||||
.post<{ field: string }>(API.USER.REQUEST_CODE(), { field })
|
||||
.then(cleanResult);
|
||||
|
||||
export const apiCheckRestoreCode = ({ code }: ApiCheckRestoreCodeRequest) =>
|
||||
api.get<ApiCheckRestoreCodeResult>(API.USER.REQUEST_CODE(code)).then(cleanResult);
|
||||
|
||||
export const apiRestoreCode = ({ code, password }: ApiRestoreCodeRequest) =>
|
||||
api
|
||||
.post<ApiRestoreCodeResult>(API.USER.REQUEST_CODE(code), { password })
|
||||
.then(cleanResult);
|
||||
|
||||
export const apiGetSocials = () =>
|
||||
api.get<ApiGetSocialsResult>(API.USER.GET_SOCIALS).then(cleanResult);
|
||||
|
||||
export const apiDropSocial = ({ id, provider }: ApiDropSocialRequest) =>
|
||||
api.delete<ApiDropSocialResult>(API.USER.DROP_SOCIAL(provider, id)).then(cleanResult);
|
||||
|
||||
export const apiAttachSocial = ({ token }: ApiAttachSocialRequest) =>
|
||||
api
|
||||
.post<ApiAttachSocialResult>(API.USER.ATTACH_SOCIAL, { token })
|
||||
.then(cleanResult);
|
||||
|
||||
export const apiLoginWithSocial = ({ token, username, password }: ApiLoginWithSocialRequest) =>
|
||||
api
|
||||
.post<ApiLoginWithSocialResult>(API.USER.LOGIN_WITH_SOCIAL, { token, username, password })
|
||||
.then(cleanResult);
|
40
src/api/auth/types.ts
Normal file
40
src/api/auth/types.ts
Normal file
|
@ -0,0 +1,40 @@
|
|||
import { INotification } from '~/types';
|
||||
import { ISocialAccount, IUser } from '~/types/auth';
|
||||
|
||||
export type ApiUserLoginRequest = Record<'username' | 'password', string>;
|
||||
export type ApiUserLoginResult = { token: string; user: IUser };
|
||||
export type ApiAuthGetUserRequest = {};
|
||||
export type ApiAuthGetUserResult = { user: IUser };
|
||||
export type ApiUpdateUserRequest = {
|
||||
user: Partial<IUser & { password: string; newPassword: string }>;
|
||||
};
|
||||
export type ApiUpdateUserResult = { user: IUser; errors: Record<Partial<keyof IUser>, string> };
|
||||
export type ApiAuthGetUserProfileRequest = { username: string };
|
||||
export type ApiAuthGetUserProfileResult = { user: IUser };
|
||||
export type ApiAuthGetUpdatesRequest = {
|
||||
exclude_dialogs: number;
|
||||
last: string;
|
||||
};
|
||||
export type ApiAuthGetUpdatesResult = {
|
||||
notifications: INotification[];
|
||||
boris: { commented_at: string };
|
||||
};
|
||||
export type ApiCheckRestoreCodeRequest = { code: string };
|
||||
export type ApiCheckRestoreCodeResult = { user: IUser };
|
||||
export type ApiRestoreCodeRequest = { code: string; password: string };
|
||||
export type ApiRestoreCodeResult = { token: string; user: IUser };
|
||||
export type ApiGetSocialsResult = { accounts: ISocialAccount[] };
|
||||
export type ApiDropSocialRequest = { id: string; provider: string };
|
||||
export type ApiDropSocialResult = { accounts: ISocialAccount[] };
|
||||
export type ApiAttachSocialRequest = { token: string };
|
||||
export type ApiAttachSocialResult = { account: ISocialAccount };
|
||||
export type ApiLoginWithSocialRequest = {
|
||||
token: string;
|
||||
username?: string;
|
||||
password?: string;
|
||||
};
|
||||
export type ApiLoginWithSocialResult = {
|
||||
token: string;
|
||||
errors: Record<string, string>;
|
||||
needs_register: boolean;
|
||||
};
|
|
@ -1,18 +1,8 @@
|
|||
import { api, cleanResult, configWithToken } from '~/utils/api';
|
||||
import { INode, IResultWithStatus } from 'src/redux/types';
|
||||
import { api, cleanResult } from '~/utils/api';
|
||||
import { API } from '~/constants/api';
|
||||
import { PostCellViewRequest, PostCellViewResult } from '~/types/node';
|
||||
import { GetSearchResultsRequest, GetSearchResultsResult } from '~/types/flow';
|
||||
|
||||
export const postNode = ({
|
||||
access,
|
||||
node,
|
||||
}: {
|
||||
access: string;
|
||||
node: INode;
|
||||
}): Promise<IResultWithStatus<INode>> =>
|
||||
api.post(API.NODE.SAVE, { node }, configWithToken(access)).then(cleanResult);
|
||||
|
||||
export const postCellView = ({ id, flow }: PostCellViewRequest) =>
|
||||
api
|
||||
.post<PostCellViewResult>(API.NODE.SET_CELL_VIEW(id), { flow })
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { IMessage } from '~/redux/types';
|
||||
import { IMessage } from '~/types';
|
||||
|
||||
export type ApiGetUserMessagesRequest = {
|
||||
username: string;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { api, cleanResult } from '~/utils/api';
|
||||
import { IComment, INode } from '~/redux/types';
|
||||
import { IComment, INode } from '~/types';
|
||||
import { API } from '~/constants/api';
|
||||
import { COMMENTS_DISPLAY } from '~/constants/node';
|
||||
import {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { IFile, IUploadProgressHandler } from '~/redux/types';
|
||||
import { IFile, IUploadProgressHandler } from '~/types';
|
||||
import { UploadTarget, UploadType } from '~/constants/uploads';
|
||||
|
||||
export type ApiUploadFileRequest = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue