From d740954f3cf6e25a1cce0a4408e315600f30bbf9 Mon Sep 17 00:00:00 2001 From: Ashutosh Date: Fri, 26 Jun 2020 07:54:57 +0530 Subject: [PATCH] feat(app-page-builder): add `useConfigureDomainDialog` hook --- .../src/utils/configureDomain.tsx | 50 +++++++++++++++---- 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/packages/app-page-builder/src/utils/configureDomain.tsx b/packages/app-page-builder/src/utils/configureDomain.tsx index f008b20dbaa..566be53feca 100644 --- a/packages/app-page-builder/src/utils/configureDomain.tsx +++ b/packages/app-page-builder/src/utils/configureDomain.tsx @@ -1,6 +1,7 @@ import React from "react"; import { css } from "emotion"; -import {i18n} from "@webiny/app/i18n"; +import { i18n } from "@webiny/app/i18n"; +import { useDialog } from "@webiny/app-admin/hooks/useDialog"; const t = i18n.ns("app-page-builder/utils"); @@ -13,13 +14,40 @@ const confirmationMessageStyles = css({ export const configureDomainTitle = t`Configure domain`; -export const ConfigureDomainMessage = ({ domain }) => ( - - No site is running at {domain} -
- Either start the server by cd apps/site && yarn start -
- or update the domain by going into{" "} - page builder settings -
-); +export const ConfigureDomainMessage = ({ domain }) => { + const isLocalHost = domain && domain.includes("localhost"); + return ( + + No site is running at {domain} +
+ {isLocalHost ? ( + + Either start the server by cd apps/site && yarn start{" "} + + ) : ( + + Either deploy the site by running yarn webiny deploy apps{" "} + + )} +
+ or update the domain by going into{" "} + page builder settings +
+ ); +}; + +export const useConfigureDomainDialog = (domain, onAccept = null) => { + const { showDialog } = useDialog(); + + return { + showConfigureDomainDialog: () => { + showDialog(, { + title: configureDomainTitle, + actions: { + accept: { label: "Refresh", onClick: onAccept }, + cancel: { label: "Cancel" } + } + }); + } + }; +};