refactor: fetch notifications over graphql query
This commit is contained in:
@@ -29,7 +29,6 @@ rm -rf .env
|
|||||||
echo "
|
echo "
|
||||||
PORT=$WEB_PORT
|
PORT=$WEB_PORT
|
||||||
REACT_APP_GRAPHQL_URL=http://localhost:$BACKEND_PORT/graphql
|
REACT_APP_GRAPHQL_URL=http://localhost:$BACKEND_PORT/graphql
|
||||||
REACT_APP_NOTIFICATIONS_URL=https://notifications.automatisch.io
|
|
||||||
" >> .env
|
" >> .env
|
||||||
cd $CURRENT_DIR
|
cd $CURRENT_DIR
|
||||||
|
|
||||||
|
5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
@@ -1,4 +1,7 @@
|
|||||||
{
|
{
|
||||||
"editor.formatOnSave": true,
|
"editor.formatOnSave": true,
|
||||||
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
||||||
|
"[javascript]": {
|
||||||
|
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
15
packages/backend/src/graphql/queries/get-notifications.ts
Normal file
15
packages/backend/src/graphql/queries/get-notifications.ts
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import axios from '../../helpers/axios-with-proxy';
|
||||||
|
|
||||||
|
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;
|
@@ -16,13 +16,14 @@ import getExecutions from './queries/get-executions';
|
|||||||
import getFlow from './queries/get-flow';
|
import getFlow from './queries/get-flow';
|
||||||
import getFlows from './queries/get-flows';
|
import getFlows from './queries/get-flows';
|
||||||
import getInvoices from './queries/get-invoices.ee';
|
import getInvoices from './queries/get-invoices.ee';
|
||||||
|
import getNotifications from './queries/get-notifications';
|
||||||
import getPaddleInfo from './queries/get-paddle-info.ee';
|
import getPaddleInfo from './queries/get-paddle-info.ee';
|
||||||
import getPaymentPlans from './queries/get-payment-plans.ee';
|
import getPaymentPlans from './queries/get-payment-plans.ee';
|
||||||
import getPermissionCatalog from './queries/get-permission-catalog.ee';
|
import getPermissionCatalog from './queries/get-permission-catalog.ee';
|
||||||
import getRole from './queries/get-role.ee';
|
import getRole from './queries/get-role.ee';
|
||||||
import getRoles from './queries/get-roles.ee';
|
import getRoles from './queries/get-roles.ee';
|
||||||
import getSamlAuthProvider from './queries/get-saml-auth-provider.ee';
|
|
||||||
import getSamlAuthProviderRoleMappings from './queries/get-saml-auth-provider-role-mappings.ee';
|
import getSamlAuthProviderRoleMappings from './queries/get-saml-auth-provider-role-mappings.ee';
|
||||||
|
import getSamlAuthProvider from './queries/get-saml-auth-provider.ee';
|
||||||
import getStepWithTestExecutions from './queries/get-step-with-test-executions';
|
import getStepWithTestExecutions from './queries/get-step-with-test-executions';
|
||||||
import getSubscriptionStatus from './queries/get-subscription-status.ee';
|
import getSubscriptionStatus from './queries/get-subscription-status.ee';
|
||||||
import getTrialStatus from './queries/get-trial-status.ee';
|
import getTrialStatus from './queries/get-trial-status.ee';
|
||||||
@@ -51,6 +52,7 @@ const queryResolvers = {
|
|||||||
getFlow,
|
getFlow,
|
||||||
getFlows,
|
getFlows,
|
||||||
getInvoices,
|
getInvoices,
|
||||||
|
getNotifications,
|
||||||
getPaddleInfo,
|
getPaddleInfo,
|
||||||
getPaymentPlans,
|
getPaymentPlans,
|
||||||
getPermissionCatalog,
|
getPermissionCatalog,
|
||||||
|
@@ -46,6 +46,7 @@ type Query {
|
|||||||
getPermissionCatalog: PermissionCatalog
|
getPermissionCatalog: PermissionCatalog
|
||||||
getRole(id: String!): Role
|
getRole(id: String!): Role
|
||||||
getRoles: [Role]
|
getRoles: [Role]
|
||||||
|
getNotifications: [Notification]
|
||||||
getSamlAuthProvider: SamlAuthProvider
|
getSamlAuthProvider: SamlAuthProvider
|
||||||
getSamlAuthProviderRoleMappings(id: String!): [SamlAuthProvidersRoleMapping]
|
getSamlAuthProviderRoleMappings(id: String!): [SamlAuthProvidersRoleMapping]
|
||||||
getSubscriptionStatus: GetSubscriptionStatus
|
getSubscriptionStatus: GetSubscriptionStatus
|
||||||
@@ -787,6 +788,13 @@ 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
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import { rule, shield, allow } from 'graphql-shield';
|
import { allow, rule, shield } from 'graphql-shield';
|
||||||
import jwt from 'jsonwebtoken';
|
import jwt from 'jsonwebtoken';
|
||||||
import User from '../models/user';
|
|
||||||
import appConfig from '../config/app';
|
import appConfig from '../config/app';
|
||||||
|
import User from '../models/user';
|
||||||
|
|
||||||
const isAuthenticated = rule()(async (_parent, _args, req) => {
|
const isAuthenticated = rule()(async (_parent, _args, req) => {
|
||||||
const token = req.headers['authorization'];
|
const token = req.headers['authorization'];
|
||||||
@@ -34,15 +34,16 @@ const authentication = shield(
|
|||||||
Query: {
|
Query: {
|
||||||
'*': isAuthenticated,
|
'*': isAuthenticated,
|
||||||
getAutomatischInfo: allow,
|
getAutomatischInfo: allow,
|
||||||
listSamlAuthProviders: allow,
|
|
||||||
healthcheck: allow,
|
|
||||||
getConfig: allow,
|
getConfig: allow,
|
||||||
|
getNotifications: allow,
|
||||||
|
healthcheck: allow,
|
||||||
|
listSamlAuthProviders: allow,
|
||||||
},
|
},
|
||||||
Mutation: {
|
Mutation: {
|
||||||
'*': isAuthenticated,
|
'*': isAuthenticated,
|
||||||
registerUser: allow,
|
|
||||||
forgotPassword: allow,
|
forgotPassword: allow,
|
||||||
login: allow,
|
login: allow,
|
||||||
|
registerUser: allow,
|
||||||
resetPassword: allow,
|
resetPassword: allow,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
7
packages/types/index.d.ts
vendored
7
packages/types/index.d.ts
vendored
@@ -448,6 +448,13 @@ type AppAuthClient = {
|
|||||||
formattedAuthDefaults: IJSONObject;
|
formattedAuthDefaults: IJSONObject;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type Notification = {
|
||||||
|
name: string;
|
||||||
|
createdAt: string;
|
||||||
|
documentationUrl: string;
|
||||||
|
description: string;
|
||||||
|
}
|
||||||
|
|
||||||
declare module 'axios' {
|
declare module 'axios' {
|
||||||
interface AxiosResponse {
|
interface AxiosResponse {
|
||||||
httpError?: IJSONObject;
|
httpError?: IJSONObject;
|
||||||
|
@@ -2,4 +2,3 @@ PORT=3001
|
|||||||
REACT_APP_GRAPHQL_URL=http://localhost:3000/graphql
|
REACT_APP_GRAPHQL_URL=http://localhost:3000/graphql
|
||||||
# HTTPS=true
|
# HTTPS=true
|
||||||
REACT_APP_BASE_URL=http://localhost:3001
|
REACT_APP_BASE_URL=http://localhost:3001
|
||||||
REACT_APP_NOTIFICATIONS_URL=https://notifications.automatisch.io
|
|
||||||
|
@@ -2,7 +2,6 @@ type Config = {
|
|||||||
[key: string]: string;
|
[key: string]: string;
|
||||||
baseUrl: string;
|
baseUrl: string;
|
||||||
graphqlUrl: string;
|
graphqlUrl: string;
|
||||||
notificationsUrl: string;
|
|
||||||
chatwootBaseUrl: string;
|
chatwootBaseUrl: string;
|
||||||
supportEmailAddress: string;
|
supportEmailAddress: string;
|
||||||
};
|
};
|
||||||
@@ -10,7 +9,6 @@ type Config = {
|
|||||||
const config: Config = {
|
const config: Config = {
|
||||||
baseUrl: process.env.REACT_APP_BASE_URL as string,
|
baseUrl: process.env.REACT_APP_BASE_URL as string,
|
||||||
graphqlUrl: process.env.REACT_APP_GRAPHQL_URL as string,
|
graphqlUrl: process.env.REACT_APP_GRAPHQL_URL as string,
|
||||||
notificationsUrl: process.env.REACT_APP_NOTIFICATIONS_URL as string,
|
|
||||||
chatwootBaseUrl: 'https://app.chatwoot.com',
|
chatwootBaseUrl: 'https://app.chatwoot.com',
|
||||||
supportEmailAddress: 'support@automatisch.io',
|
supportEmailAddress: 'support@automatisch.io',
|
||||||
};
|
};
|
||||||
|
12
packages/web/src/graphql/queries/get-notifications.ts
Normal file
12
packages/web/src/graphql/queries/get-notifications.ts
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import { gql } from '@apollo/client';
|
||||||
|
|
||||||
|
export const GET_NOTIFICATIONS = gql`
|
||||||
|
query GetNotifications {
|
||||||
|
getNotifications {
|
||||||
|
name
|
||||||
|
createdAt
|
||||||
|
documentationUrl
|
||||||
|
description
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
@@ -1,26 +1,20 @@
|
|||||||
import * as React from 'react';
|
import { useQuery } from '@apollo/client';
|
||||||
import appConfig from 'config/app';
|
import type { Notification } from '@automatisch/types';
|
||||||
|
|
||||||
interface INotification {
|
import { GET_NOTIFICATIONS } from 'graphql/queries/get-notifications';
|
||||||
name: string;
|
|
||||||
createdAt: string;
|
type UseNotificationsReturn = {
|
||||||
documentationUrl: string;
|
notifications: Notification[];
|
||||||
description: string;
|
loading: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function useNotifications(): INotification[] {
|
export default function useNotifications(): UseNotificationsReturn {
|
||||||
const [notifications, setNotifications] = React.useState<INotification[]>([]);
|
const { data, loading } = useQuery(GET_NOTIFICATIONS);
|
||||||
|
|
||||||
React.useEffect(() => {
|
const notifications = data?.getNotifications || [];
|
||||||
fetch(`${appConfig.notificationsUrl}/notifications.json`)
|
|
||||||
.then((response) => response.json())
|
|
||||||
.then((notifications) => {
|
|
||||||
if (Array.isArray(notifications) && notifications.length) {
|
|
||||||
setNotifications(notifications);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(console.error);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return notifications;
|
return {
|
||||||
|
loading,
|
||||||
|
notifications,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
@@ -10,7 +10,7 @@ type TVersionInfo = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default function useVersion(): TVersionInfo {
|
export default function useVersion(): TVersionInfo {
|
||||||
const notifications = useNotifications();
|
const { notifications } = useNotifications();
|
||||||
const { data } = useQuery(HEALTHCHECK, { fetchPolicy: 'cache-and-network' });
|
const { data } = useQuery(HEALTHCHECK, { fetchPolicy: 'cache-and-network' });
|
||||||
const version = data?.healthcheck.version;
|
const version = data?.healthcheck.version;
|
||||||
|
|
||||||
|
@@ -17,7 +17,7 @@ interface INotification {
|
|||||||
|
|
||||||
export default function Updates(): React.ReactElement {
|
export default function Updates(): React.ReactElement {
|
||||||
const formatMessage = useFormatMessage();
|
const formatMessage = useFormatMessage();
|
||||||
const notifications = useNotifications();
|
const { notifications } = useNotifications();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box sx={{ py: 3 }}>
|
<Box sx={{ py: 3 }}>
|
||||||
|
Reference in New Issue
Block a user