-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Marketplace Themes: Fixes the bug activating themes after resetting t…
…he site (#73113) * Create reducers, actions and selectors for handling the products reinstall * Add error to the state * Adding the request to reinstall the products in the activateTheme action * Fix activateTheme test
- Loading branch information
1 parent
08451d5
commit 7bca130
Showing
9 changed files
with
203 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import wpcom from 'calypso/lib/wp'; | ||
import { | ||
MARKETPLACE_PRODUCTS_REINSTALL_COMPLETED, | ||
MARKETPLACE_PRODUCTS_REINSTALL_FAILED, | ||
MARKETPLACE_PRODUCTS_REINSTALL_STARTED, | ||
MARKETPLACE_PRODUCTS_REINSTALL_NOT_STARTED, | ||
} from 'calypso/state/action-types'; | ||
import { activateTheme } from 'calypso/state/themes/actions'; | ||
import type { AnyAction } from 'redux'; | ||
import 'calypso/state/marketplace/init'; | ||
|
||
/** | ||
* Reinstall products on a site. | ||
* | ||
* @param siteId the site id | ||
* @returns Promise | ||
*/ | ||
export function productsReinstall( siteId: number, themeId: string ) { | ||
return async ( dispatch: CallableFunction ) => { | ||
dispatch( productsReinstallStarted( siteId ) ); | ||
|
||
try { | ||
await wpcom.req.get( { | ||
path: `/sites/${ siteId }/marketplace/products/reinstall`, | ||
apiNamespace: 'wpcom/v2', | ||
} ); | ||
|
||
dispatch( productsReinstallCompleted( siteId ) ); | ||
} catch ( error ) { | ||
dispatch( productsReinstallFailed( siteId, ( error as Error ).message ) ); | ||
} | ||
dispatch( activateTheme( themeId, siteId ) ); | ||
}; | ||
} | ||
|
||
export function productsReinstallStarted( siteId: number ): AnyAction { | ||
return { | ||
type: MARKETPLACE_PRODUCTS_REINSTALL_STARTED, | ||
siteId, | ||
}; | ||
} | ||
|
||
export function productsReinstallFailed( siteId: number, error: string ): AnyAction { | ||
return { | ||
type: MARKETPLACE_PRODUCTS_REINSTALL_FAILED, | ||
siteId, | ||
error, | ||
}; | ||
} | ||
|
||
export function productsReinstallCompleted( siteId: number ): AnyAction { | ||
return { | ||
type: MARKETPLACE_PRODUCTS_REINSTALL_COMPLETED, | ||
siteId, | ||
}; | ||
} | ||
|
||
export function productsReinstallNotStarted( siteId: number ): AnyAction { | ||
return { | ||
type: MARKETPLACE_PRODUCTS_REINSTALL_NOT_STARTED, | ||
siteId, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { | ||
MARKETPLACE_PRODUCTS_REINSTALL_COMPLETED, | ||
MARKETPLACE_PRODUCTS_REINSTALL_FAILED, | ||
MARKETPLACE_PRODUCTS_REINSTALL_STARTED, | ||
MARKETPLACE_PRODUCTS_REINSTALL_NOT_STARTED, | ||
} from 'calypso/state/action-types'; | ||
import { withSchemaValidation } from 'calypso/state/utils'; | ||
import { IReinstallProductsState, IReinstallProductsStatus } from '../types'; | ||
import { productsReinstallSchema } from './schema'; | ||
import type { AnyAction } from 'redux'; | ||
|
||
export const defaultState: IReinstallProductsState = {}; | ||
|
||
const productsReinstall = withSchemaValidation( | ||
productsReinstallSchema, | ||
( state = defaultState, action: AnyAction ): IReinstallProductsState => { | ||
const { type, siteId, error } = action; | ||
switch ( type ) { | ||
case MARKETPLACE_PRODUCTS_REINSTALL_STARTED: | ||
return { | ||
...state, | ||
[ siteId ]: { | ||
status: IReinstallProductsStatus.IN_PROGRESS, | ||
}, | ||
}; | ||
case MARKETPLACE_PRODUCTS_REINSTALL_COMPLETED: | ||
return { | ||
...state, | ||
[ siteId ]: { | ||
status: IReinstallProductsStatus.COMPLETED, | ||
}, | ||
}; | ||
case MARKETPLACE_PRODUCTS_REINSTALL_FAILED: | ||
return { | ||
...state, | ||
[ siteId ]: { | ||
status: IReinstallProductsStatus.FAILED, | ||
error, | ||
}, | ||
}; | ||
case MARKETPLACE_PRODUCTS_REINSTALL_NOT_STARTED: | ||
return { | ||
...state, | ||
[ siteId ]: { | ||
status: IReinstallProductsStatus.NOT_STARTED, | ||
}, | ||
}; | ||
} | ||
|
||
return state; | ||
} | ||
); | ||
|
||
export default productsReinstall; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export const productsReinstallSchema = { | ||
type: 'object', | ||
additionalProperties: false, | ||
properties: { | ||
'^\\d+$': { | ||
type: 'object', | ||
properties: { | ||
started: { type: 'boolean' }, | ||
failed: { type: 'boolean' }, | ||
completed: { type: 'boolean' }, | ||
}, | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import 'calypso/state/marketplace/init'; | ||
import { IAppState } from 'calypso/state/types'; | ||
import { IReinstallProductsStatus } from '../types'; | ||
|
||
export function isReinstallingProducts( state: IAppState, siteId: number ) { | ||
return ( | ||
state.marketplace.reinstallProducts?.[ siteId ]?.status === IReinstallProductsStatus.IN_PROGRESS | ||
); | ||
} | ||
|
||
export function failedReinstallingProducts( state: IAppState, siteId: number ) { | ||
return ( | ||
state.marketplace.reinstallProducts?.[ siteId ]?.status === IReinstallProductsStatus.FAILED | ||
); | ||
} | ||
|
||
export function completedReinstallingProducts( state: IAppState, siteId: number ) { | ||
return ( | ||
state.marketplace.reinstallProducts?.[ siteId ]?.status === IReinstallProductsStatus.COMPLETED | ||
); | ||
} | ||
|
||
export function requestedReinstallProducts( state: IAppState, siteId: number ) { | ||
return ( | ||
state.marketplace.reinstallProducts?.[ siteId ]?.status === | ||
IReinstallProductsStatus.COMPLETED || | ||
state.marketplace.reinstallProducts?.[ siteId ]?.status === IReinstallProductsStatus.FAILED | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
import { withStorageKey } from '@automattic/state-utils'; | ||
import { combineReducers } from 'calypso/state/utils'; | ||
import billingInterval from './billing-interval/reducer'; | ||
import reinstallProducts from './products-reinstall/reducer'; | ||
import purchaseFlow from './purchase-flow/reducer'; | ||
|
||
const combinedReducers = combineReducers( { | ||
purchaseFlow, | ||
billingInterval, | ||
reinstallProducts, | ||
} ); | ||
|
||
export default withStorageKey( 'marketplace', combinedReducers ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters