Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useAppFailedPendingWebhooksLazyQuery } from "@dashboard/graphql";
import type moment from "moment-timezone";
import { useMemo } from "react";
import { useCallback, useMemo } from "react";

import { getLatestFailedAttemptFromWebhooks, type LatestWebhookDeliveryWithMoment } from "./utils";

Expand Down Expand Up @@ -33,14 +33,14 @@ export const useAppsFailedDeliveries = (): AppsFailedDeliveries => {
[data?.apps?.edges],
);

const handleFetchAppsWebhooks = () => {
const handleFetchAppsWebhooks = useCallback(() => {
// Permissions are checked outside of this hook
fetchAppsWebhooks({
variables: {
canFetchAppEvents: true,
},
});
};
}, [fetchAppsWebhooks]);

return {
hasFailed: !!lastFailedWebhookDate,
Expand Down
58 changes: 32 additions & 26 deletions src/extensions/components/AppAlerts/useSidebarDotState.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { errorTracker } from "@dashboard/services/errorTracking";
import { useEffect, useRef, useState } from "react";
import { useCallback, useEffect, useRef, useState } from "react";

import { useSidebarWebhookAlertMetadata } from "./useSidebarWebhookAlertMetadata";

Expand Down Expand Up @@ -42,34 +42,40 @@ export const useSidebarDotState = (): SidebarDotState => {
}
}, [sidebarDotRemoteState]);

const handleClick = async (clickDate: string) => {
try {
await persist({
lastClickDate: clickDate,
lastFailedAttemptDate: lastFailedAttemptDateRef.current ?? "",
});
lastClickDateRef.current = clickDate;
} catch (error) {
errorTracker.captureException(error as Error);
}
};
const handleClick = useCallback(
async (clickDate: string) => {
try {
await persist({
lastClickDate: clickDate,
lastFailedAttemptDate: lastFailedAttemptDateRef.current ?? "",
});
lastClickDateRef.current = clickDate;
} catch (error) {
errorTracker.captureException(error as Error);
}
},
[persist],
);

const handleFailedAttempt = async (failedAttemptDate: string) => {
try {
await persist({
lastClickDate: lastClickDateRef.current ?? "",
lastFailedAttemptDate: failedAttemptDate,
});
lastFailedAttemptDateRef.current = failedAttemptDate;
const handleFailedAttempt = useCallback(
async (failedAttemptDate: string) => {
try {
await persist({
lastClickDate: lastClickDateRef.current ?? "",
lastFailedAttemptDate: failedAttemptDate,
});
lastFailedAttemptDateRef.current = failedAttemptDate;

// Show dot if no clicks or failed attempt is newer
if (!lastClickDateRef.current || failedAttemptDate > lastClickDateRef.current) {
setHasProblems(true);
// Show dot if no clicks or failed attempt is newer
if (!lastClickDateRef.current || failedAttemptDate > lastClickDateRef.current) {
setHasProblems(true);
}
} catch (error) {
errorTracker.captureException(error as Error);
}
} catch (error) {
errorTracker.captureException(error as Error);
}
};
},
[persist],
);

return {
handleAppsListItemClick: handleClick,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useUser } from "@dashboard/auth/useUser";
import { type MetadataInput, useUserAccountUpdateMutation } from "@dashboard/graphql";
import { useMemo } from "react";
import { useCallback, useMemo } from "react";

export const DELIVERY_ATTEMPT_KEY = "sidebar_app_webhook_alert_state";

Expand All @@ -19,20 +19,23 @@ export const useSidebarWebhookAlertMetadata = (): SidebarWebhookAlertMetadata =>

const [saveMetadata] = useUserAccountUpdateMutation();

const persist = async (metadataInput: Record<string, string>) => {
await saveMetadata({
variables: {
input: {
metadata: [
{
key: DELIVERY_ATTEMPT_KEY,
value: JSON.stringify(metadataInput),
} satisfies MetadataInput,
],
const persist = useCallback(
async (metadataInput: Record<string, string>) => {
await saveMetadata({
variables: {
input: {
metadata: [
{
key: DELIVERY_ATTEMPT_KEY,
value: JSON.stringify(metadataInput),
} satisfies MetadataInput,
],
},
},
},
});
};
});
},
[saveMetadata],
);

const sidebarDotRemoteState = useMemo(() => {
const webhookAlertMetadata = user?.metadata.find(m => m.key === DELIVERY_ATTEMPT_KEY) ?? null;
Expand Down
Loading