Skip to content

Commit

Permalink
new updates
Browse files Browse the repository at this point in the history
  • Loading branch information
suhailkakar committed Mar 4, 2024
1 parent 7331762 commit bb4da7d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
1 change: 0 additions & 1 deletion packages/www/hooks/use-api/endpoints/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ export const getWebhookLogs = async (
];

const fetchLogs = async (fromStatus, additionalFilters = [], limit = 20) => {
console.log("fromStatus", additionalFilters);
const query = qs.stringify({
limit,
cursor: fromStatus ? null : cursor,
Expand Down
23 changes: 17 additions & 6 deletions packages/www/pages/dashboard/developers/webhooks/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const WebhookDetail = () => {
successCount: 0,
});
const [loadingMore, setLoadingMore] = useState(false);

const { getWebhook, getWebhookLogs } = useApi();
const router = useRouter();
const { id } = router.query;
Expand All @@ -31,17 +30,25 @@ const WebhookDetail = () => {
}
);

const containsSuccessFilter = (logFilters) => {
return logFilters.some((filter) => filter.id === "success");
};

const { refetch: refetchLogs, isLoading: isLogsLoading } = useQuery(
["webhookLogs", id, logFilters],
() => getWebhookLogs(id, logFilters, logs ? logs.cursor : null, true),
() =>
getWebhookLogs(
id,
logFilters,
logFilters.length > 0 ? null : logs.cursor,
true
),
{
enabled: !!id,
onSuccess: (data) => {
const containsSuccessFilter = logFilters.some(
(filter) => filter.id === "success"
);
const isSuccess = containsSuccessFilter(logFilters);

if (containsSuccessFilter) {
if (isSuccess) {
setLogs({
...data,
data: loadingMore ? [...logs.data, ...data.data] : data.data,
Expand All @@ -64,6 +71,10 @@ const WebhookDetail = () => {
const handleLogFilters = async (filters) => {
if (filters.length === 0) {
setLogFilters([]);
setLogs({
...logs,
cursor: null,
});
refetchLogs();
return;
}
Expand Down

0 comments on commit bb4da7d

Please sign in to comment.