nicolium: rename a utility type that should probably not exist
Signed-off-by: nicole mikołajczyk <git@mkljczk.pl>
This commit is contained in:
@ -22,7 +22,7 @@ import { createAccount } from '@/actions/accounts';
|
||||
import { createApp } from '@/actions/apps';
|
||||
import { fetchMeSuccess, fetchMeFail } from '@/actions/me';
|
||||
import { obtainOAuthToken, revokeOAuthToken } from '@/actions/oauth';
|
||||
import { type PlfeResponse, getClient } from '@/api';
|
||||
import { type NicoliumResponse, getClient } from '@/api';
|
||||
import * as BuildConfig from '@/build-config';
|
||||
import { selectAccount } from '@/queries/accounts/selectors';
|
||||
import { queryClient } from '@/queries/client';
|
||||
@ -235,7 +235,7 @@ const loadCredentials = (token: string, accountUrl: string) => (dispatch: AppDis
|
||||
const logIn = (username: string, password: string) => (dispatch: AppDispatch) =>
|
||||
dispatch(createAuthApp())
|
||||
.then(() => dispatch(createUserToken(normalizeUsername(username), password)))
|
||||
.catch((error: { response: PlfeResponse }) => {
|
||||
.catch((error: { response: NicoliumResponse }) => {
|
||||
if (error.response?.json?.error === 'mfa_required') {
|
||||
// If MFA is required, throw the error and handle it in the component.
|
||||
throw error;
|
||||
|
||||
@ -10,7 +10,7 @@ import type { RootState, Store } from '@/store';
|
||||
let store: Store;
|
||||
import('@/store').then((value) => (store = value.store)).catch(() => {});
|
||||
|
||||
type PlfeResponse<T = any> = Response & { data: string; json: T };
|
||||
type NicoliumResponse<T = any> = Response & { data: string; json: T };
|
||||
|
||||
/**
|
||||
* Dumb client for grabbing static files.
|
||||
@ -44,7 +44,7 @@ const staticFetch = async (input: URL | RequestInfo, init?: RequestInit) => {
|
||||
url,
|
||||
data,
|
||||
json,
|
||||
} as any as PlfeResponse;
|
||||
} as any as NicoliumResponse;
|
||||
};
|
||||
|
||||
const getClient = (state: RootState | (() => RootState) = store?.getState()) => {
|
||||
@ -53,4 +53,4 @@ const getClient = (state: RootState | (() => RootState) = store?.getState()) =>
|
||||
return state.auth.client;
|
||||
};
|
||||
|
||||
export { type PlfeResponse, staticFetch, getClient };
|
||||
export { type NicoliumResponse, staticFetch, getClient };
|
||||
|
||||
@ -32,7 +32,7 @@ import toast from '@/toast';
|
||||
|
||||
import { AccountMenu } from './account-menu';
|
||||
|
||||
import type { PlfeResponse } from '@/api';
|
||||
import type { NicoliumResponse } from '@/api';
|
||||
import type { Account as AccountEntity } from 'pl-api';
|
||||
|
||||
const messages = defineMessages({
|
||||
@ -97,7 +97,7 @@ const Header: React.FC<IHeader> = ({ account }) => {
|
||||
|
||||
const createAndNavigateToChat = useMutation({
|
||||
mutationFn: (accountId: string) => getOrCreateChatByAccountId(accountId),
|
||||
onError: (error: { response: PlfeResponse }) => {
|
||||
onError: (error: { response: NicoliumResponse }) => {
|
||||
const data = error.response.json;
|
||||
toast.error(data?.error);
|
||||
},
|
||||
|
||||
@ -18,7 +18,7 @@ import Blankslate from './blankslate';
|
||||
import EmptyResultsBlankslate from './empty-results-blankslate';
|
||||
import Results from './results';
|
||||
|
||||
import type { PlfeResponse } from '@/api';
|
||||
import type { NicoliumResponse } from '@/api';
|
||||
|
||||
const messages = defineMessages({
|
||||
placeholder: { id: 'chat_search.placeholder', defaultMessage: 'Type a name' },
|
||||
@ -50,7 +50,7 @@ const ChatSearch: React.FC<IChatSearch> = ({ isMainPage = false }) => {
|
||||
|
||||
const handleClickOnSearchResult = useMutation({
|
||||
mutationFn: (accountId: string) => getOrCreateChatByAccountId(accountId),
|
||||
onError: (error: { response: PlfeResponse }) => {
|
||||
onError: (error: { response: NicoliumResponse }) => {
|
||||
const data = error.response?.json;
|
||||
toast.error(data?.error);
|
||||
},
|
||||
|
||||
@ -11,7 +11,7 @@ import toast from '@/toast';
|
||||
import ChatComposer from './chat-composer';
|
||||
import ChatMessageList from './chat-message-list';
|
||||
|
||||
import type { PlfeResponse } from '@/api';
|
||||
import type { NicoliumResponse } from '@/api';
|
||||
import type { Chat as ChatEntity, MediaAttachment } from 'pl-api';
|
||||
|
||||
const fileKeyGen = (): number => Math.floor(Math.random() * 0x10000);
|
||||
@ -73,7 +73,7 @@ const Chat: React.FC<IChat> = ({ chat, inputRef, className }) => {
|
||||
onSuccess: () => {
|
||||
setErrorMessage(undefined);
|
||||
},
|
||||
onError: (error: { response: PlfeResponse }, _variables) => {
|
||||
onError: (error: { response: NicoliumResponse }, _variables) => {
|
||||
const message = error.response?.json?.error;
|
||||
setErrorMessage(message ?? intl.formatMessage(messages.failedToSend));
|
||||
},
|
||||
|
||||
@ -17,7 +17,7 @@ import { useRegistrationStatus } from '@/hooks/use-registration-status';
|
||||
import { getRedirectUrl } from '@/utils/redirect';
|
||||
import { isStandalone } from '@/utils/state';
|
||||
|
||||
import type { PlfeResponse } from '@/api';
|
||||
import type { NicoliumResponse } from '@/api';
|
||||
|
||||
const SignUpPanel = () => {
|
||||
const dispatch = useAppDispatch();
|
||||
@ -54,7 +54,7 @@ const SignUpPanel = () => {
|
||||
setShouldRedirect(true);
|
||||
}
|
||||
})
|
||||
.catch((error: { response: PlfeResponse }) => {
|
||||
.catch((error: { response: NicoliumResponse }) => {
|
||||
const data: any = error.response?.json;
|
||||
if (data?.error === 'mfa_required') {
|
||||
setMfaAuthNeeded(true);
|
||||
|
||||
@ -10,7 +10,7 @@ import toast from '@/toast';
|
||||
import ConfirmationStep from './steps/confirmation-step';
|
||||
import DetailsStep from './steps/details-step';
|
||||
|
||||
import type { PlfeResponse } from '@/api';
|
||||
import type { NicoliumResponse } from '@/api';
|
||||
import type { BaseModalProps } from '@/features/ui/components/modal-root';
|
||||
import type { CreateGroupParams, Group } from 'pl-api';
|
||||
|
||||
@ -58,7 +58,7 @@ const CreateGroupModal: React.FC<BaseModalProps> = ({ onClose }) => {
|
||||
onError(error) {
|
||||
const msg = v.safeParse(
|
||||
v.object({ error: v.string() }),
|
||||
(error as { response?: PlfeResponse })?.response?.json,
|
||||
(error as { response?: NicoliumResponse })?.response?.json,
|
||||
);
|
||||
if (msg.success) {
|
||||
toast.error(msg.output.error);
|
||||
|
||||
@ -17,7 +17,7 @@ import { useModalsActions } from '@/stores/modals';
|
||||
import { getRedirectUrl } from '@/utils/redirect';
|
||||
import { isStandalone } from '@/utils/state';
|
||||
|
||||
import type { PlfeResponse } from '@/api';
|
||||
import type { NicoliumResponse } from '@/api';
|
||||
|
||||
const LoginPage = () => {
|
||||
const dispatch = useAppDispatch();
|
||||
@ -53,7 +53,7 @@ const LoginPage = () => {
|
||||
setShouldRedirect(true);
|
||||
}
|
||||
})
|
||||
.catch((error: { response: PlfeResponse }) => {
|
||||
.catch((error: { response: NicoliumResponse }) => {
|
||||
const data: any = error.response?.json;
|
||||
if (data?.error === 'mfa_required') {
|
||||
setMfaAuthNeeded(true);
|
||||
|
||||
@ -21,7 +21,7 @@ import { useGroupQuery, useUpdateGroupMutation } from '@/queries/groups/use-grou
|
||||
import toast from '@/toast';
|
||||
import { unescapeHTML } from '@/utils/html';
|
||||
|
||||
import type { PlfeResponse } from '@/api';
|
||||
import type { NicoliumResponse } from '@/api';
|
||||
|
||||
const messages = defineMessages({
|
||||
heading: { id: 'navigation_bar.edit_group', defaultMessage: 'Edit Group' },
|
||||
@ -79,7 +79,7 @@ const EditGroup: React.FC = () => {
|
||||
toast.success(intl.formatMessage(messages.groupSaved));
|
||||
},
|
||||
onError(error) {
|
||||
const response = (error as { response?: PlfeResponse })?.response;
|
||||
const response = (error as { response?: NicoliumResponse })?.response;
|
||||
const message = response?.json?.error;
|
||||
|
||||
if (response?.status === 422 && typeof message !== 'undefined') {
|
||||
|
||||
@ -18,7 +18,7 @@ import {
|
||||
} from '@/queries/groups/use-group-members';
|
||||
import toast from '@/toast';
|
||||
|
||||
import type { PlfeResponse } from '@/api';
|
||||
import type { NicoliumResponse } from '@/api';
|
||||
import type { Account as AccountEntity } from 'pl-api';
|
||||
|
||||
const messages = defineMessages({
|
||||
@ -90,7 +90,7 @@ const GroupMembershipRequests: React.FC = () => {
|
||||
acceptGroupMembershipRequest(account.id, {
|
||||
onSuccess: () => resolve(),
|
||||
onError: (error) => {
|
||||
const { response } = error as unknown as { response: PlfeResponse };
|
||||
const { response } = error as unknown as { response: NicoliumResponse };
|
||||
|
||||
let message = intl.formatMessage(messages.authorizeFail, { name: account.username });
|
||||
if (response?.status === 409) {
|
||||
@ -108,7 +108,7 @@ const GroupMembershipRequests: React.FC = () => {
|
||||
rejectGroupMembershipRequest(account.id, {
|
||||
onSuccess: () => resolve(),
|
||||
onError: (error) => {
|
||||
const { response } = error as unknown as { response: PlfeResponse };
|
||||
const { response } = error as unknown as { response: NicoliumResponse };
|
||||
|
||||
let message = intl.formatMessage(messages.rejectFail, { name: account.username });
|
||||
if (response?.status === 409) {
|
||||
|
||||
@ -6,10 +6,10 @@ import { queryKeys } from '@/queries/keys';
|
||||
|
||||
import { useAccount } from './use-account';
|
||||
|
||||
import type { PlfeResponse } from '@/api';
|
||||
import type { NicoliumResponse } from '@/api';
|
||||
|
||||
const getResponseStatus = (error: unknown) =>
|
||||
(error as { response?: PlfeResponse })?.response?.status;
|
||||
(error as { response?: NicoliumResponse })?.response?.status;
|
||||
|
||||
const useAccountLookup = (acct: string | undefined, withRelationship = false) => {
|
||||
const client = useClient();
|
||||
|
||||
@ -8,12 +8,12 @@ import { useCredentialAccount } from '@/queries/accounts/use-account-credentials
|
||||
import { useRelationshipQuery } from '@/queries/accounts/use-relationship';
|
||||
import { queryKeys } from '@/queries/keys';
|
||||
|
||||
import type { PlfeResponse } from '@/api';
|
||||
import type { NicoliumResponse } from '@/api';
|
||||
|
||||
const ADMIN_PERMISSION = 0x1n;
|
||||
|
||||
const getResponseStatus = (error: unknown) =>
|
||||
(error as { response?: PlfeResponse })?.response?.status;
|
||||
(error as { response?: NicoliumResponse })?.response?.status;
|
||||
|
||||
const hasAdminPermission = (permissions?: string): boolean | undefined => {
|
||||
if (!permissions) return undefined;
|
||||
|
||||
@ -34,7 +34,7 @@ import { coerceObject } from '@/schemas/utils';
|
||||
import KVStore from '@/storage/kv-store';
|
||||
import { validId, isURL, parseBaseURL } from '@/utils/auth';
|
||||
|
||||
import type { PlfeResponse } from '@/api';
|
||||
import type { NicoliumResponse } from '@/api';
|
||||
|
||||
const instance = (() => {
|
||||
try {
|
||||
@ -326,7 +326,7 @@ const persistAuthAccount = (account: CredentialAccount) => {
|
||||
|
||||
const deleteForbiddenToken = (
|
||||
state: State | Draft<State>,
|
||||
error: { response: PlfeResponse },
|
||||
error: { response: NicoliumResponse },
|
||||
token: string,
|
||||
) => {
|
||||
if (error.response && [401, 403].includes(error.response.status)) {
|
||||
|
||||
@ -12,13 +12,13 @@ import {
|
||||
type MeAction,
|
||||
} from '@/actions/me';
|
||||
|
||||
import type { PlfeResponse } from '@/api';
|
||||
import type { NicoliumResponse } from '@/api';
|
||||
|
||||
type Me = string | null | false;
|
||||
|
||||
const initialState: Me = null;
|
||||
|
||||
const handleForbidden = (state: Me, error: { response: PlfeResponse }) => {
|
||||
const handleForbidden = (state: Me, error: { response: NicoliumResponse }) => {
|
||||
if (error.response?.status && [401, 403].includes(error.response.status)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -5,7 +5,7 @@ import { defineMessages, type MessageDescriptor } from 'react-intl';
|
||||
import Toast from './components/ui/toast';
|
||||
import { httpErrorMessages } from './utils/errors';
|
||||
|
||||
import type { PlfeResponse } from './api';
|
||||
import type { NicoliumResponse } from './api';
|
||||
import type { LinkOptions } from '@tanstack/react-router';
|
||||
|
||||
type ToastText = string | MessageDescriptor;
|
||||
@ -45,7 +45,7 @@ const messages = defineMessages({
|
||||
unexpectedMessage: { id: 'alert.unexpected.message', defaultMessage: 'Something went wrong.' },
|
||||
});
|
||||
|
||||
const showAlertForError = (networkError: { response: PlfeResponse }) => {
|
||||
const showAlertForError = (networkError: { response: NicoliumResponse }) => {
|
||||
if (networkError?.response) {
|
||||
const { json, status, statusText } = networkError.response;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user