feat: initialise template

This commit is contained in:
etwodev
2025-11-11 15:19:09 +00:00
commit 911693f3c3
74 changed files with 8676 additions and 0 deletions

View File

@@ -0,0 +1,63 @@
import { useState, useCallback } from 'react';
import {
ApiError,
APIResponse,
apiClient,
isApiResponse,
isApiError,
} from '..';
export interface UpdateClientRequest {
client_name: string;
redirect_uri: string;
regenerate_secret: boolean;
}
export interface UpdateClientResponse {
client_secret?: string;
}
interface UseUpdateClient {
isLoading: boolean;
error: ApiError | null;
data: APIResponse<UpdateClientResponse> | null;
updateClient: (
clientId: string,
payload: UpdateClientRequest,
) => Promise<void>;
}
export const useUpdateClient = (): UseUpdateClient => {
const [isLoading, setIsLoading] = useState(false);
const [error, setError] = useState<ApiError | null>(null);
const [data, setData] = useState<APIResponse<UpdateClientResponse> | null>(
null,
);
const updateClient = useCallback(
(clientId: string, payload: UpdateClientRequest): Promise<void> => {
setIsLoading(true);
setError(null);
setData(null);
const url = `v1/client/${clientId}`;
return apiClient()
.patch<UpdateClientResponse>(url, payload)
.then(res => {
if (isApiResponse<UpdateClientResponse>(res)) {
setData(res);
} else if (isApiError(res)) {
setError(res);
} else {
setError({ message: 'Received unknown response structure.' });
}
})
.catch(() => setError({ message: 'Network or unexpected error' }))
.finally(() => setIsLoading(false));
},
[],
);
return { isLoading, error, data, updateClient };
};