Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/nexcess domains alt #144

Draft
wants to merge 28 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
0ece713
chore: Jorge's sitebuilder work
chumpgrub Nov 5, 2022
abe4fff
chore: Jorge's storebuilder work
chumpgrub Nov 5, 2022
0f17877
chore: Jorge's wme-ui work
chumpgrub Nov 5, 2022
448ec62
chore: pnpm-lock commit
chumpgrub Nov 5, 2022
aca6e11
chore: Update package version to 1.6.0-alpha.4
chumpgrub Nov 5, 2022
2837a28
chore: Fix text regression
chumpgrub Nov 6, 2022
b66d02e
chore: Increment alpha package version
chumpgrub Nov 6, 2022
cc7b0d3
chore: Replace lorem ipsum
chumpgrub Nov 7, 2022
6a3986b
chore: Makes search icon clickable on FindDomain screen
chumpgrub Nov 7, 2022
44a4dd1
chore: Add styles to make ListItemCheckout button from appearing clic…
chumpgrub Nov 8, 2022
529b3fb
chore: Update placeholder text
chumpgrub Nov 8, 2022
45c110b
fix: Remove old StoreBuilder styles from theme object
chumpgrub Nov 8, 2022
fc0a28b
chore: Increment alpha version
chumpgrub Nov 8, 2022
7e6aeee
chore: Commit mix-manifest.json change
chumpgrub Nov 8, 2022
f6cdce5
fix: Update redirect to use nexcess domain and UUID value
chumpgrub Nov 8, 2022
c0529eb
chore: Increment alpha package
chumpgrub Nov 8, 2022
f80eae6
chore: Fixes indenting
chumpgrub Nov 8, 2022
92f74a5
chore: Increment alpha version
chumpgrub Nov 8, 2022
730eae5
chore: Leverage new pruchaseFlowUrl property
chumpgrub Nov 9, 2022
3b316bd
chore: Increment alpha version
chumpgrub Nov 9, 2022
279d4b8
chore: Add new content to VerifyDomain screen
chumpgrub Nov 9, 2022
7d7722e
chore: Fix indentations
chumpgrub Nov 9, 2022
858bab0
chore: Increment alpha package
chumpgrub Nov 9, 2022
3290478
fix: Adds support for non 12 month terms
chumpgrub Nov 9, 2022
9707d13
chore: Lint fixes
chumpgrub Nov 9, 2022
d617b8c
chore: Conflict resolved
chumpgrub Nov 9, 2022
982c67a
Merge branch 'main' into feature/nexcess-domains-alt
jorgemasta Nov 10, 2022
683f7ed
Merge pull request #128 from moderntribe/feature/nexcess-domains-term…
chumpgrub Nov 10, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions packages/sitebuilder/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@moderntribe/sitebuilder",
"version": "1.5.0",
"version": "1.6.0-alpha.10",
"description": "SiteBuilder foundation",
"main": "dist/index.js",
"files": [
Expand All @@ -22,17 +22,18 @@
"author": "",
"dependencies": {
"@moderntribe/wme-ui": "workspace:*",
"@moderntribe/wme-utils": "workspace:*"
"@moderntribe/wme-utils": "workspace:*",
"@tanstack/react-query": "^4.14.3"
},
"peerDependencies": {
"@wordpress/element": "^4.12.0",
"@wordpress/html-entities": "^3.14.0",
"@wordpress/i18n": "^4.14.0",
"@emotion/react": "^11.9.3",
"@emotion/styled": "^11.9.3",
"@mui/icons-material": "^5.8.4",
"@mui/material": "^5.9.2",
"@mui/utils": "^5.9.1",
"@wordpress/element": "^4.12.0",
"@wordpress/html-entities": "^3.14.0",
"@wordpress/i18n": "^4.14.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.4.2"
Expand Down
52 changes: 52 additions & 0 deletions packages/sitebuilder/sitebuilder.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,58 @@ declare global {
disable?: boolean;
hidePagination?: boolean;
}
export interface Domain {
domain: string
is_available: boolean
package: {
id: number
identity: string
metadata: DomainMetadata
addons: DomainAddon[]
auto_renew: boolean
bandwidth: number
billing_type: string
environment_type: string
is_wildcard: boolean
label: string
name: string
orderable_terms: DomainOrderableTerms
term_fees: DomainTermFees
tld: DomainTld
trial_period: number
type: string
}
pricing: any[]
tld: DomainTld
}
interface DomainAddon {
id: number
identity: string
metadata: DomainMetadata
description: string
monthly_fee: string
name: string
term_fees: DomainTermFees
type: string
}
interface DomainTermFees {
[key: string]: string
}

interface DomainOrderableTerms {
[key: string]: string
}

interface DomainTld {
id: number
identity: string
metadata: DomainMetadata
}

interface DomainMetadata {
scope: string
uri: string
}

interface Window {
ppcp_onboarding_productionCallback: (authCode: string, sharedId: string) => void;
Expand Down
27 changes: 17 additions & 10 deletions packages/sitebuilder/src/SiteBuilder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,34 @@ import React, { lazy } from 'react';
import { ThemeProvider, createTheme } from '@mui/material';
import { theme as WME_THEME } from '@moderntribe/wme-ui';
import { HashRouter, Routes, Route, Navigate } from 'react-router-dom';
import {
QueryClient,
QueryClientProvider
} from '@tanstack/react-query';
import SiteBuilderProvider from '@sb/contexts/SiteBuilderProvider';
import WizardProvider from '@sb/contexts/WizardProvider';
import WizardWrapper from '@sb/wizards/WizardWrapper';
import Loadable from '@sb/components/Loadable';
import { SB_THEME } from '@sb/constants';

const SetupScreen = Loadable(lazy(() => import('@sb/setup/SetupScreen')));
const SetupScreen: (props: any) => JSX.Element = Loadable(lazy(() => import('@sb/setup/SetupScreen')));

const siteBuilderTheme = createTheme(WME_THEME, SB_THEME);
const queryClient = new QueryClient();

const SiteBuilder = () => (
<ThemeProvider theme={ siteBuilderTheme }>
<SiteBuilderProvider>
<HashRouter>
<Routes>
<Route path="/" element={ <SetupScreen fullscreen={ true } /> } />
<Route path="/wizard/*" element={ <WizardProvider><WizardWrapper /></WizardProvider> } />
<Route path="*" element={ <Navigate to="/" /> } />
</Routes>
</HashRouter>
</SiteBuilderProvider>
<QueryClientProvider client={ queryClient }>
<SiteBuilderProvider>
<HashRouter>
<Routes>
<Route path="/" element={ <SetupScreen fullscreen={ true } /> } />
<Route path="/wizard/*" element={ <WizardProvider><WizardWrapper /></WizardProvider> } />
<Route path="*" element={ <Navigate to="/" /> } />
</Routes>
</HashRouter>
</SiteBuilderProvider>
</QueryClientProvider>
</ThemeProvider>
);

Expand Down
6 changes: 0 additions & 6 deletions packages/sitebuilder/src/constants/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@ declare module '@mui/material/styles/createPalette' {

let theme = {
palette: {
primary: {
main: '#303F9F',
dark: '#2A3353',
grey: '#949494',
white: '#FFF',
},
text: {
primary: '#2A3353',
secondary: '#2A3353',
Expand Down
84 changes: 37 additions & 47 deletions packages/sitebuilder/src/contexts/GoLiveProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface GoLiveProviderContextInterface {
setIsLoading: (loading: boolean) => void;
getHasDomainNextText: (hasDomain: string) => void;
setHasDomain: (hasDomain: string) => void;
setShowGetDomain: (show: boolean) => void;
setShowPurchaseNavigation: (show: boolean) => void;
}

export interface DomainVerficationSuccessInterface {
Expand Down Expand Up @@ -72,6 +72,7 @@ export const GoLiveContext = createContext<GoLiveProviderContextInterface | null

const GoLiveProvider = ({ children }: { children: React.ReactNode }) => {
const [goLiveState, setGoLiveState] = useState<GoLiveInterface>(GoLiveData());
const { selectedDomains } = goLiveState;

const goLiveNonce = GO_LIVE_PROPS.ajax?.nonce || '';
const goLiveAction = GO_LIVE_PROPS.ajax?.action || '';
Expand All @@ -80,6 +81,7 @@ const GoLiveProvider = ({ children }: { children: React.ReactNode }) => {

const navigate = useNavigate();
const [searchParams, setSearchParams] = useSearchParams();
const purchaseNavigation = searchParams.get('purchase') === 'true';

const activeStep = searchParams.get('step')
? Number(searchParams.get('step'))
Expand All @@ -94,46 +96,35 @@ const GoLiveProvider = ({ children }: { children: React.ReactNode }) => {
}, [retryVerfication]);

useEffect(() => {
if (activeStep === 3) {
if (! capturedDomain) {
navigate('/wizard/go-live');
}

if (
goLiveState.verificationStatus && ! (
goLiveState.verificationStatus === 'connected' ||
goLiveState.verificationStatus === 'advanced'
)
) {
navigate('/wizard/go-live');
}

if (goLiveState.verificationStatus === 'error') {
navigate('/wizard/go-live?step=2');
if (activeStep === 2) {
if (purchaseNavigation) {
if (selectedDomains.length === 0) {
searchParams.set('step', '1');
setSearchParams(searchParams);
}
}
}

if (activeStep === 1 && goLiveState.hasDomain !== null) {
const { steps, hasDomain, showGetDomain } = goLiveState;

steps[ 0 ].nextText = continueStr;
steps[ 0 ].hideBack = true;

if (hasDomain === 'no') {
steps[ 0 ].nextText = showGetDomain ? haveDomain : getDomain;
}

if (hasDomain === 'no' && showGetDomain) {
steps[ 0 ].disableNext = true;
steps[ 0 ].hideBack = false;
if (activeStep === 3) {
if (! purchaseNavigation) {
if (! capturedDomain) {
navigate('/wizard/go-live');
}

if (
goLiveState.verificationStatus && ! (
goLiveState.verificationStatus === 'connected' ||
goLiveState.verificationStatus === 'advanced'
)
) {
navigate('/wizard/go-live');
}

if (goLiveState.verificationStatus === 'error') {
navigate('/wizard/go-live?step=2');
}
}

setGoLiveState({
...goLiveState,
steps
});
}
}, [activeStep, goLiveState.showGetDomain]);
}, [activeStep, purchaseNavigation]);

const submitGoLiveForm = () => {
const { steps, showLogoutButton } = goLiveState;
Expand Down Expand Up @@ -312,7 +303,7 @@ const GoLiveProvider = ({ children }: { children: React.ReactNode }) => {
const getHasDomainNextText = (hasDomain:string) => {
switch (hasDomain) {
case 'yes':
return goLiveState.showGetDomain ? haveDomain : continueStr;
return haveDomain;
case 'no':
return getDomain;
default:
Expand All @@ -331,14 +322,13 @@ const GoLiveProvider = ({ children }: { children: React.ReactNode }) => {
});
};

const setShowGetDomain = (show:boolean) => {
const { steps } = goLiveState;
steps[ 0 ].nextText = haveDomain;
setGoLiveState({
...goLiveState,
showGetDomain: show,
steps
});
const setShowPurchaseNavigation = (show: boolean) => {
if (show) {
searchParams.set('purchase', 'true');
} else {
searchParams.delete('purchase');
}
setSearchParams(searchParams);
};

return (
Expand All @@ -349,7 +339,7 @@ const GoLiveProvider = ({ children }: { children: React.ReactNode }) => {
submitDomainVerification,
setIsLoading,
setHasDomain,
setShowGetDomain,
setShowPurchaseNavigation,
handleDomainVerificationRequest,
getHasDomainNextText
} }>
Expand Down
3 changes: 2 additions & 1 deletion packages/sitebuilder/src/contexts/WizardProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ const WizardProvider = ({ children }: { children: React.ReactNode }) => {
if (typeof targetStep !== 'number') {
return;
}
setSearchParams({ step: String(targetStep) });
searchParams.set('step', String(targetStep));
setSearchParams(searchParams);
};

const goToNextStep = () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/sitebuilder/src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export * from './useCreatePurchaseFlow';
export * from './useFindDomain';
export * from './useFirstTimeConfiguration';
export * from './useLookAndFeel';
export * from './useGoLive';
Expand Down
51 changes: 51 additions & 0 deletions packages/sitebuilder/src/hooks/useCreatePurchaseFlow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { useMutation } from '@tanstack/react-query';
import { handleActionRequest } from '@moderntribe/wme-utils';
import { GO_LIVE_PROPS } from '@sb/constants';

export interface Response {
action: string
data: any
callback_url: string
return_url: any
uuid: string
site_id: number
outcome: Outcome
}

export interface Outcome {
status: string
details: Details
}

export interface Details {
id: number
identity: string
scope: string
purchased_domain: string
}

async function createPurchaseFlow(domains: { domainName: string, packageId: number}[]) {
const goLiveNonce = GO_LIVE_PROPS.ajax?.nonce || '';
const goLiveAction = GO_LIVE_PROPS.ajax?.action || '';
const response: any = await handleActionRequest({
_wpnonce: goLiveNonce,
action: goLiveAction,
sub_action: 'create-purchase-flow',
domains: domains.map(({ domainName, packageId }) => ({ domain_name: domainName, package_id: packageId })),
});
return response as Response;
}

export function useCreatePurchaseFlow() {
const goLivePurchaseFlowUrl = GO_LIVE_PROPS?.purchaseFlowUrl || '';
const mutation = useMutation(
createPurchaseFlow,
{
onSuccess: (data) => {
window.location.href = goLivePurchaseFlowUrl.replace('UUID', data.uuid);
},
}
);

return mutation;
}
Loading