This reverts commit 4ce7fc6987, to take
more time to address PR comments
This commit is contained in:
@ -1,43 +0,0 @@
|
||||
import { useCallback, useState } from 'react';
|
||||
import { ClientConfig } from '~/generated/graphql';
|
||||
import { getClientConfig } from '../utils/clientConfigUtils';
|
||||
|
||||
interface UseClientConfigResult {
|
||||
data: { clientConfig: ClientConfig } | undefined;
|
||||
loading: boolean;
|
||||
error: Error | undefined;
|
||||
fetchClientConfig: () => Promise<void>;
|
||||
refetchClientConfig: () => Promise<void>;
|
||||
}
|
||||
|
||||
export const useClientConfig = (): UseClientConfigResult => {
|
||||
const [data, setData] = useState<{ clientConfig: ClientConfig } | undefined>(
|
||||
undefined,
|
||||
);
|
||||
const [loading, setLoading] = useState<boolean>(false);
|
||||
const [error, setError] = useState<Error | undefined>(undefined);
|
||||
|
||||
const fetchClientConfig = useCallback(async () => {
|
||||
setLoading(true);
|
||||
setError(undefined);
|
||||
|
||||
try {
|
||||
const clientConfig = await getClientConfig();
|
||||
setData({ clientConfig });
|
||||
} catch (err) {
|
||||
setError(
|
||||
err instanceof Error ? err : new Error('Failed to fetch client config'),
|
||||
);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
return {
|
||||
data,
|
||||
loading,
|
||||
error,
|
||||
fetchClientConfig,
|
||||
refetchClientConfig: fetchClientConfig,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user