Fix api keys refresh (#2283)

* Move code to dedicated function

* Format cached data with proper typename
This commit is contained in:
martmull
2023-10-30 17:48:34 +01:00
committed by GitHub
parent 3fc1b74d9c
commit 236742e88c
2 changed files with 26 additions and 14 deletions

View File

@ -69,25 +69,32 @@ export const SettingsDevelopersApiKeyDetail = () => {
}
};
const createIntegration = async (
name: string,
newExpiresAt: string | null,
) => {
return await insertOneApiKey({
variables: {
data: {
name: name,
expiresAt: newExpiresAt,
},
},
update: (_cache, { data }) => {
if (data?.createOneApiKey) {
triggerOptimisticEffects('ApiKey', [data?.createOneApiKey]);
}
},
});
};
const regenerateApiKey = async () => {
if (apiKeyData?.name) {
const newExpiresAt = computeNewExpirationDate(
apiKeyData.expiresAt,
apiKeyData.createdAt,
);
const apiKey = await insertOneApiKey({
variables: {
data: {
name: apiKeyData.name,
expiresAt: newExpiresAt,
},
},
update: (_cache, { data }) => {
if (data?.createOneApiKey) {
triggerOptimisticEffects('ApiKey', [data?.createOneApiKey]);
}
},
});
const apiKey = await createIntegration(apiKeyData.name, newExpiresAt);
await deleteIntegration(false);
if (apiKey.data?.createOneApiKey) {
setGeneratedApi(