refactor: rewrite useNotifications with RQ
This commit is contained in:

committed by
kattoczko

parent
b68aff76a1
commit
d808afd21b
@@ -1,16 +0,0 @@
|
|||||||
import axios from '../../helpers/axios-with-proxy.js';
|
|
||||||
|
|
||||||
const NOTIFICATIONS_URL =
|
|
||||||
'https://notifications.automatisch.io/notifications.json';
|
|
||||||
|
|
||||||
const getNotifications = async () => {
|
|
||||||
try {
|
|
||||||
const { data: notifications = [] } = await axios.get(NOTIFICATIONS_URL);
|
|
||||||
|
|
||||||
return notifications;
|
|
||||||
} catch (err) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export default getNotifications;
|
|
@@ -7,7 +7,6 @@ import getConnectedApps from './queries/get-connected-apps.js';
|
|||||||
import getDynamicData from './queries/get-dynamic-data.js';
|
import getDynamicData from './queries/get-dynamic-data.js';
|
||||||
import getDynamicFields from './queries/get-dynamic-fields.js';
|
import getDynamicFields from './queries/get-dynamic-fields.js';
|
||||||
import getFlow from './queries/get-flow.js';
|
import getFlow from './queries/get-flow.js';
|
||||||
import getNotifications from './queries/get-notifications.js';
|
|
||||||
import getStepWithTestExecutions from './queries/get-step-with-test-executions.js';
|
import getStepWithTestExecutions from './queries/get-step-with-test-executions.js';
|
||||||
import testConnection from './queries/test-connection.js';
|
import testConnection from './queries/test-connection.js';
|
||||||
|
|
||||||
@@ -21,7 +20,6 @@ const queryResolvers = {
|
|||||||
getDynamicData,
|
getDynamicData,
|
||||||
getDynamicFields,
|
getDynamicFields,
|
||||||
getFlow,
|
getFlow,
|
||||||
getNotifications,
|
|
||||||
getStepWithTestExecutions,
|
getStepWithTestExecutions,
|
||||||
testConnection,
|
testConnection,
|
||||||
};
|
};
|
||||||
|
@@ -18,7 +18,6 @@ type Query {
|
|||||||
): [SubstepArgument]
|
): [SubstepArgument]
|
||||||
getBillingAndUsage: GetBillingAndUsage
|
getBillingAndUsage: GetBillingAndUsage
|
||||||
getConfig(keys: [String]): JSONObject
|
getConfig(keys: [String]): JSONObject
|
||||||
getNotifications: [Notification]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Mutation {
|
type Mutation {
|
||||||
@@ -665,13 +664,6 @@ input UpdateAppAuthClientInput {
|
|||||||
active: Boolean
|
active: Boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
type Notification {
|
|
||||||
name: String
|
|
||||||
createdAt: String
|
|
||||||
documentationUrl: String
|
|
||||||
description: String
|
|
||||||
}
|
|
||||||
|
|
||||||
schema {
|
schema {
|
||||||
query: Query
|
query: Query
|
||||||
mutation: Mutation
|
mutation: Mutation
|
||||||
|
@@ -43,7 +43,6 @@ export const authenticationRules = {
|
|||||||
Query: {
|
Query: {
|
||||||
'*': isAuthenticatedRule,
|
'*': isAuthenticatedRule,
|
||||||
getConfig: allow,
|
getConfig: allow,
|
||||||
getNotifications: allow,
|
|
||||||
},
|
},
|
||||||
Mutation: {
|
Mutation: {
|
||||||
'*': isAuthenticatedRule,
|
'*': isAuthenticatedRule,
|
||||||
|
@@ -1,11 +0,0 @@
|
|||||||
import { gql } from '@apollo/client';
|
|
||||||
export const GET_NOTIFICATIONS = gql`
|
|
||||||
query GetNotifications {
|
|
||||||
getNotifications {
|
|
||||||
name
|
|
||||||
createdAt
|
|
||||||
documentationUrl
|
|
||||||
description
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`;
|
|
16
packages/web/src/hooks/useAutomatischNotifications.js
Normal file
16
packages/web/src/hooks/useAutomatischNotifications.js
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import { useQuery } from '@tanstack/react-query';
|
||||||
|
import api from 'helpers/api';
|
||||||
|
|
||||||
|
export default function useAutomatischNotifications() {
|
||||||
|
const query = useQuery({
|
||||||
|
queryKey: ['automatisch', 'notifications'],
|
||||||
|
queryFn: async ({ signal }) => {
|
||||||
|
const { data } = await api.get(`/v1/automatisch/notifications`, {
|
||||||
|
signal,
|
||||||
|
});
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return query;
|
||||||
|
}
|
@@ -1,10 +0,0 @@
|
|||||||
import { useQuery } from '@apollo/client';
|
|
||||||
import { GET_NOTIFICATIONS } from 'graphql/queries/get-notifications';
|
|
||||||
export default function useNotifications() {
|
|
||||||
const { data, loading } = useQuery(GET_NOTIFICATIONS);
|
|
||||||
const notifications = data?.getNotifications || [];
|
|
||||||
return {
|
|
||||||
loading,
|
|
||||||
notifications,
|
|
||||||
};
|
|
||||||
}
|
|
@@ -1,11 +1,11 @@
|
|||||||
import { compare } from 'compare-versions';
|
import { compare } from 'compare-versions';
|
||||||
import { useQuery } from '@tanstack/react-query';
|
import { useQuery } from '@tanstack/react-query';
|
||||||
|
|
||||||
import useNotifications from 'hooks/useNotifications';
|
import useAutomatischNotifications from 'hooks/useAutomatischNotifications';
|
||||||
import api from 'helpers/api';
|
import api from 'helpers/api';
|
||||||
|
|
||||||
export default function useVersion() {
|
export default function useVersion() {
|
||||||
const { notifications } = useNotifications();
|
const { data: notificationsData } = useAutomatischNotifications();
|
||||||
const { data } = useQuery({
|
const { data } = useQuery({
|
||||||
queryKey: ['automatischVersion'],
|
queryKey: ['automatischVersion'],
|
||||||
queryFn: async ({ signal }) => {
|
queryFn: async ({ signal }) => {
|
||||||
@@ -17,6 +17,7 @@ export default function useVersion() {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
const version = data?.data?.version;
|
const version = data?.data?.version;
|
||||||
|
const notifications = notificationsData?.data || [];
|
||||||
|
|
||||||
const newVersionCount = notifications.reduce((count, notification) => {
|
const newVersionCount = notifications.reduce((count, notification) => {
|
||||||
if (!version) return 0;
|
if (!version) return 0;
|
||||||
|
@@ -9,14 +9,15 @@ import PageTitle from 'components/PageTitle';
|
|||||||
import * as URLS from 'config/urls';
|
import * as URLS from 'config/urls';
|
||||||
import useAutomatischInfo from 'hooks/useAutomatischInfo';
|
import useAutomatischInfo from 'hooks/useAutomatischInfo';
|
||||||
import useFormatMessage from 'hooks/useFormatMessage';
|
import useFormatMessage from 'hooks/useFormatMessage';
|
||||||
import useNotifications from 'hooks/useNotifications';
|
import useAutomatischNotifications from 'hooks/useAutomatischNotifications';
|
||||||
|
|
||||||
export default function Updates() {
|
export default function Updates() {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const formatMessage = useFormatMessage();
|
const formatMessage = useFormatMessage();
|
||||||
const { notifications } = useNotifications();
|
const { data: notificationsData } = useAutomatischNotifications();
|
||||||
const { data: automatischInfo, isPending } = useAutomatischInfo();
|
const { data: automatischInfo, isPending } = useAutomatischInfo();
|
||||||
const isMation = automatischInfo?.data.isMation;
|
const isMation = automatischInfo?.data.isMation;
|
||||||
|
const notifications = notificationsData?.data || [];
|
||||||
|
|
||||||
React.useEffect(
|
React.useEffect(
|
||||||
function redirectToHomepageInMation() {
|
function redirectToHomepageInMation() {
|
||||||
|
Reference in New Issue
Block a user