Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
Pwuts committed Oct 14, 2024
1 parent 042e098 commit e6dc463
Showing 1 changed file with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {
// --8<-- [start:CredentialsProviderNames]
const CREDENTIALS_PROVIDER_NAMES = ["github", "google", "notion"] as const;

export type CredentialsProviderName = (typeof CREDENTIALS_PROVIDER_NAMES)[number];
export type CredentialsProviderName =
(typeof CREDENTIALS_PROVIDER_NAMES)[number];

const providerDisplayNames: Record<CredentialsProviderName, string> = {
github: "GitHub",
Expand Down Expand Up @@ -122,14 +123,22 @@ export default function CredentialsProvider({

/** Wraps `AutoGPTServerAPI.deleteCredentials`, and removes the credentials from the internal store. */
const deleteCredentials = useCallback(
async (provider: CredentialsProviderName, id: string): Promise<CredentialsDeleteResponse> => {
async (
provider: CredentialsProviderName,
id: string,
): Promise<CredentialsDeleteResponse> => {
const result = await api.deleteCredentials(provider, id);
setProviders((prev) => {
if (!prev || !prev[provider]) return prev;

const updatedProvider = { ...prev[provider] };
updatedProvider.savedApiKeys = updatedProvider.savedApiKeys.filter(cred => cred.id !== id);
updatedProvider.savedOAuthCredentials = updatedProvider.savedOAuthCredentials.filter(cred => cred.id !== id);
updatedProvider.savedApiKeys = updatedProvider.savedApiKeys.filter(
(cred) => cred.id !== id,
);
updatedProvider.savedOAuthCredentials =
updatedProvider.savedOAuthCredentials.filter(
(cred) => cred.id !== id,
);

return {
...prev,
Expand Down Expand Up @@ -174,7 +183,8 @@ export default function CredentialsProvider({
createAPIKeyCredentials: (
credentials: APIKeyCredentialsCreatable,
) => createAPIKeyCredentials(provider, credentials),
deleteCredentials: (id: string) => deleteCredentials(provider, id),
deleteCredentials: (id: string) =>
deleteCredentials(provider, id),
},
}));
});
Expand Down

0 comments on commit e6dc463

Please sign in to comment.