chore: Use types from the web package

This commit is contained in:
Faruk AYDIN
2024-01-15 13:30:48 +01:00
parent 7831f2925b
commit 159931a6ea
77 changed files with 934 additions and 378 deletions

View File

@@ -1,22 +1,16 @@
import { useQuery } from '@apollo/client';
import { IApp } from '@automatisch/types';
import { IApp } from 'types';
import { GET_APP } from 'graphql/queries/get-app';
type QueryResponse = {
getApp: IApp;
}
};
export default function useApp(key: string) {
const {
data,
loading
} = useQuery<QueryResponse>(
GET_APP,
{
variables: { key }
}
);
const { data, loading } = useQuery<QueryResponse>(GET_APP, {
variables: { key },
});
const app = data?.getApp;
return {

View File

@@ -1,5 +1,5 @@
import { useLazyQuery } from '@apollo/client';
import { AppAuthClient } from '@automatisch/types';
import { AppAuthClient } from 'types';
import * as React from 'react';
import { GET_APP_AUTH_CLIENT } from 'graphql/queries/get-app-auth-client.ee';

View File

@@ -1,5 +1,5 @@
import { useLazyQuery } from '@apollo/client';
import { AppAuthClient } from '@automatisch/types';
import { AppAuthClient } from 'types';
import * as React from 'react';
import { GET_APP_AUTH_CLIENTS } from 'graphql/queries/get-app-auth-clients.ee';

View File

@@ -1,23 +1,17 @@
import { useQuery } from '@apollo/client';
import { AppConfig } from '@automatisch/types';
import { AppConfig } from 'types';
import { GET_APP_CONFIG } from 'graphql/queries/get-app-config.ee';
type QueryResponse = {
getAppConfig: AppConfig;
}
};
export default function useAppConfig(key: string) {
const {
data,
loading
} = useQuery<QueryResponse>(
GET_APP_CONFIG,
{
variables: { key },
context: { autoSnackbar: false }
}
);
const { data, loading } = useQuery<QueryResponse>(GET_APP_CONFIG, {
variables: { key },
context: { autoSnackbar: false },
});
const appConfig = data?.getAppConfig;
return {

View File

@@ -1,5 +1,5 @@
import { useQuery } from '@apollo/client';
import { IApp } from '@automatisch/types';
import { IApp } from 'types';
import { GET_APPS } from 'graphql/queries/get-apps';

View File

@@ -1,4 +1,4 @@
import { IApp } from '@automatisch/types';
import { IApp } from 'types';
import * as React from 'react';
import { processStep } from 'helpers/authenticationSteps';
@@ -10,14 +10,18 @@ type UseAuthenticateAppParams = {
appAuthClientId?: string;
useShared?: boolean;
connectionId?: string;
}
};
type AuthenticatePayload = {
fields?: Record<string, string>;
appAuthClientId?: string;
}
};
function getSteps(auth: IApp['auth'], hasConnection: boolean, useShared: boolean) {
function getSteps(
auth: IApp['auth'],
hasConnection: boolean,
useShared: boolean
) {
if (hasConnection) {
if (useShared) {
return auth?.sharedReconnectionSteps;
@@ -34,26 +38,17 @@ function getSteps(auth: IApp['auth'], hasConnection: boolean, useShared: boolean
}
export default function useAuthenticateApp(payload: UseAuthenticateAppParams) {
const {
appKey,
appAuthClientId,
connectionId,
useShared = false,
} = payload;
const { appKey, appAuthClientId, connectionId, useShared = false } = payload;
const { app } = useApp(appKey);
const [
authenticationInProgress,
setAuthenticationInProgress
] = React.useState(false);
const [authenticationInProgress, setAuthenticationInProgress] =
React.useState(false);
const steps = getSteps(app?.auth, !!connectionId, useShared);
const authenticate = React.useMemo(() => {
if (!steps?.length) return;
return async function authenticate(payload: AuthenticatePayload = {}) {
const {
fields,
} = payload;
const { fields } = payload;
setAuthenticationInProgress(true);
const response: Record<string, any> = {
@@ -62,7 +57,7 @@ export default function useAuthenticateApp(payload: UseAuthenticateAppParams) {
connection: {
id: connectionId,
},
fields
fields,
};
let stepIndex = 0;
@@ -90,7 +85,7 @@ export default function useAuthenticateApp(payload: UseAuthenticateAppParams) {
setAuthenticationInProgress(false);
}
}
};
}, [steps, appKey, appAuthClientId, connectionId]);
return {

View File

@@ -2,15 +2,21 @@ import * as React from 'react';
import { useQuery } from '@apollo/client';
import { useLocation } from 'react-router-dom';
import { DateTime } from 'luxon';
import { TSubscription } from '@automatisch/types';
import { TSubscription } from 'types';
import { GET_BILLING_AND_USAGE } from 'graphql/queries/get-billing-and-usage.ee';
function transform(billingAndUsageData: NonNullable<UseBillingAndUsageDataReturn>) {
function transform(
billingAndUsageData: NonNullable<UseBillingAndUsageDataReturn>
) {
const nextBillDate = billingAndUsageData.subscription.nextBillDate;
const nextBillDateTitle = nextBillDate.title;
const nextBillDateTitleDateObject = DateTime.fromMillis(Number(nextBillDateTitle));
const formattedNextBillDateTitle = nextBillDateTitleDateObject.isValid ? nextBillDateTitleDateObject.toFormat('LLL dd, yyyy') : nextBillDateTitle;
const nextBillDateTitleDateObject = DateTime.fromMillis(
Number(nextBillDateTitle)
);
const formattedNextBillDateTitle = nextBillDateTitleDateObject.isValid
? nextBillDateTitleDateObject.toFormat('LLL dd, yyyy')
: nextBillDateTitle;
return {
...billingAndUsageData,
@@ -19,8 +25,8 @@ function transform(billingAndUsageData: NonNullable<UseBillingAndUsageDataReturn
nextBillDate: {
...billingAndUsageData.subscription.nextBillDate,
title: formattedNextBillDateTitle,
}
}
},
},
};
}
@@ -28,27 +34,35 @@ type UseBillingAndUsageDataReturn = {
subscription: TSubscription;
usage: {
task: number;
}
};
} | null;
export default function useBillingAndUsageData(): UseBillingAndUsageDataReturn {
const location = useLocation();
const state = location.state as { checkoutCompleted: boolean };
const { data, loading, startPolling, stopPolling } = useQuery(GET_BILLING_AND_USAGE);
const { data, loading, startPolling, stopPolling } = useQuery(
GET_BILLING_AND_USAGE
);
const checkoutCompleted = state?.checkoutCompleted;
const hasSubscription = !!data?.getBillingAndUsage?.subscription?.status;
React.useEffect(function pollDataUntilSubscriptionIsCreated() {
if (checkoutCompleted && !hasSubscription) {
startPolling(1000);
}
}, [checkoutCompleted, hasSubscription, startPolling]);
React.useEffect(
function pollDataUntilSubscriptionIsCreated() {
if (checkoutCompleted && !hasSubscription) {
startPolling(1000);
}
},
[checkoutCompleted, hasSubscription, startPolling]
);
React.useEffect(function stopPollingWhenSubscriptionIsCreated() {
if (checkoutCompleted && hasSubscription) {
stopPolling();
}
}, [checkoutCompleted, hasSubscription, stopPolling]);
React.useEffect(
function stopPollingWhenSubscriptionIsCreated() {
if (checkoutCompleted && hasSubscription) {
stopPolling();
}
},
[checkoutCompleted, hasSubscription, stopPolling]
);
if (loading) return null;

View File

@@ -1,14 +1,16 @@
import { useQuery } from '@apollo/client';
import { IJSONObject } from '@automatisch/types';
import { IJSONObject } from 'types';
import { GET_CONFIG } from 'graphql/queries/get-config.ee';
type QueryResponse = {
getConfig: IJSONObject;
}
};
export default function useConfig(keys?: string[]) {
const { data, loading } = useQuery<QueryResponse>(GET_CONFIG, { variables: { keys } });
const { data, loading } = useQuery<QueryResponse>(GET_CONFIG, {
variables: { keys },
});
return {
config: data?.getConfig,

View File

@@ -1,5 +1,5 @@
import { useQuery } from '@apollo/client';
import { IUser } from '@automatisch/types';
import { IUser } from 'types';
import { GET_CURRENT_USER } from 'graphql/queries/get-current-user';

View File

@@ -4,11 +4,7 @@ import { useFormContext } from 'react-hook-form';
import set from 'lodash/set';
import type { UseFormReturn } from 'react-hook-form';
import isEqual from 'lodash/isEqual';
import type {
IField,
IFieldDropdownSource,
IJSONObject,
} from '@automatisch/types';
import type { IField, IFieldDropdownSource, IJSONObject } from 'types';
import { GET_DYNAMIC_DATA } from 'graphql/queries/get-dynamic-data';

View File

@@ -8,7 +8,7 @@ import type {
IField,
IFieldDropdownAdditionalFields,
IJSONObject,
} from '@automatisch/types';
} from 'types';
import { GET_DYNAMIC_FIELDS } from 'graphql/queries/get-dynamic-fields';

View File

@@ -1,10 +1,10 @@
import { useQuery } from '@apollo/client';
import { TInvoice } from '@automatisch/types';
import { TInvoice } from 'types';
import { GET_INVOICES } from 'graphql/queries/get-invoices.ee';
type UseInvoicesReturn = {
invoices: TInvoice[],
invoices: TInvoice[];
loading: boolean;
};
@@ -13,6 +13,6 @@ export default function useInvoices(): UseInvoicesReturn {
return {
invoices: data?.getInvoices || [],
loading: loading
loading: loading,
};
}

View File

@@ -1,12 +1,12 @@
import { useQuery } from '@apollo/client';
import type { Notification } from '@automatisch/types';
import type { Notification } from 'types';
import { GET_NOTIFICATIONS } from 'graphql/queries/get-notifications';
type UseNotificationsReturn = {
notifications: Notification[];
loading: boolean;
}
};
export default function useNotifications(): UseNotificationsReturn {
const { data, loading } = useQuery(GET_NOTIFICATIONS);

View File

@@ -1,6 +1,6 @@
import { useQuery } from '@apollo/client';
import { TPaymentPlan } from '@automatisch/types';
import { TPaymentPlan } from 'types';
import { GET_PAYMENT_PLANS } from 'graphql/queries/get-payment-plans.ee';
type UsePaymentPlansReturn = {
@@ -13,6 +13,6 @@ export default function usePaymentPlans(): UsePaymentPlansReturn {
return {
plans: data?.getPaymentPlans || [],
loading
loading,
};
}

View File

@@ -1,5 +1,5 @@
import { useQuery } from '@apollo/client';
import { IPermissionCatalog } from '@automatisch/types';
import { IPermissionCatalog } from 'types';
import { GET_PERMISSION_CATALOG } from 'graphql/queries/get-permission-catalog.ee';

View File

@@ -1,6 +1,6 @@
import * as React from 'react';
import { useLazyQuery } from '@apollo/client';
import { IRole } from '@automatisch/types';
import { IRole } from 'types';
import { GET_ROLE } from 'graphql/queries/get-role.ee';

View File

@@ -1,17 +1,19 @@
import { useQuery } from '@apollo/client';
import { IRole } from '@automatisch/types';
import { IRole } from 'types';
import { GET_ROLES } from 'graphql/queries/get-roles.ee';
type QueryResponse = {
getRoles: IRole[];
}
};
export default function useRoles() {
const { data, loading } = useQuery<QueryResponse>(GET_ROLES, { context: { autoSnackbar: false } });
const { data, loading } = useQuery<QueryResponse>(GET_ROLES, {
context: { autoSnackbar: false },
});
return {
roles: data?.getRoles || [],
loading
loading,
};
}

View File

@@ -1,6 +1,6 @@
import { QueryResult, useQuery } from '@apollo/client';
import { TSamlAuthProvider } from '@automatisch/types';
import { TSamlAuthProvider } from 'types';
import { GET_SAML_AUTH_PROVIDER } from 'graphql/queries/get-saml-auth-provider';
type UseSamlAuthProviderReturn = {

View File

@@ -1,6 +1,6 @@
import * as React from 'react';
import { useLazyQuery } from '@apollo/client';
import { TSamlAuthProviderRole } from '@automatisch/types';
import { TSamlAuthProviderRole } from 'types';
import { GET_SAML_AUTH_PROVIDER_ROLE_MAPPINGS } from 'graphql/queries/get-saml-auth-provider-role-mappings';

View File

@@ -1,6 +1,6 @@
import { useQuery } from '@apollo/client';
import { TSamlAuthProvider } from '@automatisch/types';
import { TSamlAuthProvider } from 'types';
import { LIST_SAML_AUTH_PROVIDERS } from 'graphql/queries/list-saml-auth-providers.ee';
type UseSamlAuthProvidersReturn = {

View File

@@ -1,12 +1,12 @@
import * as React from 'react';
import { useLazyQuery } from '@apollo/client';
import { IUser } from '@automatisch/types';
import { IUser } from 'types';
import { GET_USER } from 'graphql/queries/get-user';
type QueryResponse = {
getUser: IUser;
}
};
export default function useUser(userId?: string) {
const [getUser, { data, loading }] = useLazyQuery<QueryResponse>(GET_USER);
@@ -15,14 +15,14 @@ export default function useUser(userId?: string) {
if (userId) {
getUser({
variables: {
id: userId
}
id: userId,
},
});
}
}, [userId]);
return {
user: data?.getUser,
loading
loading,
};
}

View File

@@ -1,5 +1,5 @@
import { useQuery } from '@apollo/client';
import { IUser } from '@automatisch/types';
import { IUser } from 'types';
import { GET_USERS } from 'graphql/queries/get-users';