From 14ca3eb18c4bd642fdb9347f3cb019960ef757e0 Mon Sep 17 00:00:00 2001 From: Giuseppe Ciotola <30926550+gciotola@users.noreply.github.com> Date: Thu, 2 May 2024 16:29:29 +0200 Subject: [PATCH] fix: update loading ui to use SkeletonTemplate instead of PageSkeleton --- packages/app/src/components/Form/Provider.tsx | 5 +- .../app/src/components/WebhookCallback.tsx | 80 ++++++++++-------- packages/app/src/components/WebhookInfos.tsx | 48 ++++++----- .../app/src/components/WebhookTopCard.tsx | 7 +- .../components/WebhookTriggerActionButton.tsx | 47 +++++------ packages/app/src/pages/EventCallbacksList.tsx | 7 -- packages/app/src/pages/WebhookCreate.tsx | 7 -- packages/app/src/pages/WebhookDelete.tsx | 84 +++++++++---------- packages/app/src/pages/WebhookDetails.tsx | 54 ++++++------ packages/app/src/pages/WebhookEdit.tsx | 44 +++++----- 10 files changed, 183 insertions(+), 200 deletions(-) diff --git a/packages/app/src/components/Form/Provider.tsx b/packages/app/src/components/Form/Provider.tsx index 03369fd..224e299 100644 --- a/packages/app/src/components/Form/Provider.tsx +++ b/packages/app/src/components/Form/Provider.tsx @@ -1,4 +1,4 @@ -import type { CommerceLayerClient } from '@commercelayer/sdk' +import { useCoreSdkProvider } from '@commercelayer/app-elements' import type { WebhookFormContextValue } from 'App' import { createContext, @@ -12,7 +12,6 @@ import { reducer } from './reducer' interface WebhookFormProviderProps { webhookId: string - sdkClient: CommerceLayerClient children: | ((props: WebhookFormContextValue) => React.ReactNode) | React.ReactNode @@ -23,10 +22,10 @@ export const useWebhookFormContext = (): WebhookFormContextValue => useContext(Context) export function WebhookFormProvider({ - sdkClient, webhookId, children }: WebhookFormProviderProps): JSX.Element { + const { sdkClient } = useCoreSdkProvider() const [state, dispatch] = useReducer(reducer, initialState) const fetchJob = useCallback(async () => { diff --git a/packages/app/src/components/WebhookCallback.tsx b/packages/app/src/components/WebhookCallback.tsx index b0eeb5a..e2475e4 100644 --- a/packages/app/src/components/WebhookCallback.tsx +++ b/packages/app/src/components/WebhookCallback.tsx @@ -1,43 +1,49 @@ -import { InputReadonly, Section, Spacer } from '@commercelayer/app-elements' +import { + InputReadonly, + Section, + Spacer, + withSkeletonTemplate +} from '@commercelayer/app-elements' import type { Webhook } from '@commercelayer/sdk' -import type { FC } from 'react' interface WebhookCallbackProps { webhook: Webhook } -export const WebhookCallback: FC = ({ webhook }) => { - return ( -
- - - - - - Used to verify the{' '} - - callback authenticity - - . - - ) - }} - /> - -
- ) -} +export const WebhookCallback = withSkeletonTemplate( + ({ webhook }) => { + return ( +
+ + + + + + Used to verify the{' '} + + callback authenticity + + . + + ) + }} + /> + +
+ ) + } +) diff --git a/packages/app/src/components/WebhookInfos.tsx b/packages/app/src/components/WebhookInfos.tsx index e0a57c0..e215a08 100644 --- a/packages/app/src/components/WebhookInfos.tsx +++ b/packages/app/src/components/WebhookInfos.tsx @@ -1,27 +1,33 @@ -import { ListItem, Section, Text } from '@commercelayer/app-elements' +import { + ListItem, + Section, + Text, + withSkeletonTemplate +} from '@commercelayer/app-elements' import type { Webhook } from '@commercelayer/sdk' -import type { FC } from 'react' interface WebhookInfosProps { webhook: Webhook } -export const WebhookInfos: FC = ({ webhook }) => { - return ( -
- {webhook.topic != null ? ( - - Topic - {webhook.topic} - - ) : null} - {webhook.include_resources != null && - webhook.include_resources.length > 0 ? ( - - Includes - {webhook.include_resources.join(', ')} - - ) : null} -
- ) -} +export const WebhookInfos = withSkeletonTemplate( + ({ webhook }) => { + return ( +
+ {webhook.topic != null ? ( + + Topic + {webhook.topic} + + ) : null} + {webhook.include_resources != null && + webhook.include_resources.length > 0 ? ( + + Includes + {webhook.include_resources.join(', ')} + + ) : null} +
+ ) + } +) diff --git a/packages/app/src/components/WebhookTopCard.tsx b/packages/app/src/components/WebhookTopCard.tsx index 5b07298..637c689 100644 --- a/packages/app/src/components/WebhookTopCard.tsx +++ b/packages/app/src/components/WebhookTopCard.tsx @@ -11,14 +11,15 @@ import { ListDetails, Spacer, Text, - useTokenProvider + useTokenProvider, + withSkeletonTemplate } from '@commercelayer/app-elements' import type { FC } from 'react' import { useRoute } from 'wouter' import { WebhookCircuit } from './WebhookCircuit' import { WebhookTriggerActionButton } from './WebhookTriggerActionButton' -export const WebhookTopCard: FC = () => { +export const WebhookTopCard: FC = withSkeletonTemplate(() => { const { canUser, user } = useTokenProvider() const [, params] = useRoute(appRoutes.details.path) const webhookId = params?.webhookId ?? '' @@ -76,4 +77,4 @@ export const WebhookTopCard: FC = () => { ) -} +}) diff --git a/packages/app/src/components/WebhookTriggerActionButton.tsx b/packages/app/src/components/WebhookTriggerActionButton.tsx index c490373..491586d 100644 --- a/packages/app/src/components/WebhookTriggerActionButton.tsx +++ b/packages/app/src/components/WebhookTriggerActionButton.tsx @@ -3,35 +3,32 @@ import { getWebhookTriggerActionName } from '#data/dictionaries' import { useTriggerAttribute } from '#hooks/useTriggerAttribute' -import { Button } from '@commercelayer/app-elements' +import { Button, withSkeletonTemplate } from '@commercelayer/app-elements' import type { Webhook } from '@commercelayer/sdk' -import type { FC } from 'react' - interface WebhookTriggerActionButtonProps { webhook: Webhook } -export const WebhookTriggerActionButton: FC< - WebhookTriggerActionButtonProps -> = ({ webhook }) => { - const triggerAction = getWebhookTriggerAction(webhook) - const label = getWebhookTriggerActionName(triggerAction.triggerAttribute) - const { isLoading, dispatch } = useTriggerAttribute(webhook.id) +export const WebhookTriggerActionButton = + withSkeletonTemplate(({ webhook }) => { + const triggerAction = getWebhookTriggerAction(webhook) + const label = getWebhookTriggerActionName(triggerAction.triggerAttribute) + const { isLoading, dispatch } = useTriggerAttribute(webhook.id) - return ( - - ) -} + return ( + + ) + }) diff --git a/packages/app/src/pages/EventCallbacksList.tsx b/packages/app/src/pages/EventCallbacksList.tsx index 9264224..bd193d4 100644 --- a/packages/app/src/pages/EventCallbacksList.tsx +++ b/packages/app/src/pages/EventCallbacksList.tsx @@ -4,9 +4,7 @@ import { Button, EmptyState, PageLayout, - PageSkeleton, ResourceList, - useCoreSdkProvider, useTokenProvider } from '@commercelayer/app-elements' import type { FC } from 'react' @@ -14,7 +12,6 @@ import { Link, useLocation, useRoute } from 'wouter' export const EventCallbacksList: FC = () => { const { settings, canUser } = useTokenProvider() - const { sdkClient } = useCoreSdkProvider() const [, setLocation] = useLocation() const [, params] = useRoute(appRoutes.webhookEventCallbacks.path) @@ -49,10 +46,6 @@ export const EventCallbacksList: FC = () => { ) } - if (sdkClient == null) { - return - } - return ( { const { settings, canUser } = useTokenProvider() - const { sdkClient } = useCoreSdkProvider() const [, setLocation] = useLocation() - if (sdkClient == null) { - return - } - if (!canUser('create', 'webhooks')) { return ( { ) } - return isLoading ? ( - - ) : webhook == null ? ( + return webhook == null ? ( ) : ( - { - setLocation(appRoutes.details.makePath({ webhookId })) - }, - label: `Cancel`, - icon: 'x' - }} - gap='only-top' - overlay - > - - - - This action cannot be undone, proceed with caution. - - - - - + + { + setLocation(appRoutes.details.makePath({ webhookId })) + }, + label: `Cancel`, + icon: 'x' + }} + gap='only-top' + overlay + > + + + + This action cannot be undone, proceed with caution. + + + + + + ) } diff --git a/packages/app/src/pages/WebhookDetails.tsx b/packages/app/src/pages/WebhookDetails.tsx index 34667d9..1a8f69a 100644 --- a/packages/app/src/pages/WebhookDetails.tsx +++ b/packages/app/src/pages/WebhookDetails.tsx @@ -12,9 +12,8 @@ import { EmptyState, Icon, PageLayout, - PageSkeleton, + SkeletonTemplate, Spacer, - useCoreSdkProvider, useTokenProvider } from '@commercelayer/app-elements' import type { FC } from 'react' @@ -22,7 +21,6 @@ import { Link, useLocation, useRoute } from 'wouter' export const WebhookDetails: FC = () => { const { settings, canUser } = useTokenProvider() - const { sdkClient } = useCoreSdkProvider() const [, params] = useRoute(appRoutes.details.path) const [, setLocation] = useLocation() @@ -54,10 +52,6 @@ export const WebhookDetails: FC = () => { ) } - if (sdkClient == null) { - return - } - const contextMenuEdit = canUser('update', 'webhooks') && ( { /> ) - return isLoading ? ( - - ) : webhook == null ? ( + return webhook == null ? ( ) : ( - { - setLocation(appRoutes.list.makePath({})) - }, - label: `Webhooks`, - icon: 'arrowLeft' - }} - actionButton={contextMenu} - > - - - - - - - - + + { + setLocation(appRoutes.list.makePath({})) + }, + label: `Webhooks`, + icon: 'arrowLeft' + }} + actionButton={contextMenu} + > + + + + + + + + + ) } diff --git a/packages/app/src/pages/WebhookEdit.tsx b/packages/app/src/pages/WebhookEdit.tsx index 43207d2..c7ab215 100644 --- a/packages/app/src/pages/WebhookEdit.tsx +++ b/packages/app/src/pages/WebhookEdit.tsx @@ -6,8 +6,7 @@ import { Button, EmptyState, PageLayout, - PageSkeleton, - useCoreSdkProvider, + SkeletonTemplate, useTokenProvider } from '@commercelayer/app-elements' import type { FC } from 'react' @@ -15,7 +14,6 @@ import { Link, useLocation, useRoute } from 'wouter' export const WebhookEdit: FC = () => { const { settings, canUser } = useTokenProvider() - const { sdkClient } = useCoreSdkProvider() const [, params] = useRoute(appRoutes.editWebhook.path) const [, setLocation] = useLocation() @@ -46,32 +44,28 @@ export const WebhookEdit: FC = () => { ) } - if (sdkClient == null) { - return - } - return ( - + {({ state: { isLoading, data } }) => - isLoading ? ( - - ) : data == null ? ( + isLoading ? null : data == null ? ( ) : ( - { - setLocation(appRoutes.list.makePath({ webhookId })) - }, - label: 'Cancel', - icon: 'x' - }} - overlay - > - - + + { + setLocation(appRoutes.list.makePath({ webhookId })) + }, + label: 'Cancel', + icon: 'x' + }} + overlay + > + + + ) }