Skip to content

Commit

Permalink
feat(SPV-915): show backend returned error message on failed contacts…
Browse files Browse the repository at this point in the history
… search
  • Loading branch information
chris-4chain committed Aug 21, 2024
1 parent 488954f commit 591cafe
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const ContactsTable: FC = () => {
const sortedContacts = useSortedContacts(contacts);

if (error) {
return <ErrorBar errorMsg="Failed to load contacts" />;
return <ErrorBar errorMsg={error} />;
}

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ export const ContactUpsertModal: FC<ContactUpsertModal> = ({
await upsertContact(paymail, name, phone ? { phoneNumber: phone } : undefined);
onSuccess();
} catch (error) {
console.log('🚀 ~ onSubmit ~ error:', error);
setError(errorMessage(error));
} finally {
setLoading(false);
Expand Down
15 changes: 8 additions & 7 deletions src/providers/contacts/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@ import { PaginationParams } from '@/api/types';
import { usePikeContactsEnabled } from '@/hooks/useFeatureFlags';
import { FC, PropsWithChildren, createContext, useCallback, useEffect, useMemo, useState } from 'react';
import { useAuthorization } from '../authorization';
import { errorMessage } from '@/utils/errorMessage';

type ContactsContextValue = {
contacts: Contact[] | null;
refresh: () => void;
loading: boolean;
error: boolean;
error: string;
};

export const ContactsContext = createContext<ContactsContextValue>(null as never);

export const ContactsProvider: FC<PropsWithChildren> = ({ children }) => {
const [loading, setLoading] = useState(false);
const [error, setError] = useState(false);
const [error, setError] = useState('');
const [contacts, setContacts] = useState<Contact[] | null>(null);
const pikeContactsEnabled = usePikeContactsEnabled()
const pikeContactsEnabled = usePikeContactsEnabled();
const { authorization } = useAuthorization();

const load = useCallback(async () => {
Expand All @@ -27,17 +28,17 @@ export const ContactsProvider: FC<PropsWithChildren> = ({ children }) => {
}
setLoading(true);
try {
const paginationParams : PaginationParams = {
const paginationParams: PaginationParams = {
page: 1,
page_size: 1000,
order: 'paymail',
sort: 'asc',
}
};
const contactsResponse = await searchContacts(paginationParams);
setContacts(contactsResponse.content);
} catch {
} catch (e: unknown) {
setContacts(null);
setError(true);
setError(errorMessage(e));
} finally {
setLoading(false);
}
Expand Down

0 comments on commit 591cafe

Please sign in to comment.