|
|
|
|
|
import wpcomRequest from 'wpcom-proxy-request'; |
|
|
import type { |
|
|
CurrentTheme, |
|
|
SiteDetails, |
|
|
Domain, |
|
|
SiteSettings, |
|
|
Dispatch, |
|
|
NewSiteErrorResponse, |
|
|
} from './types'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getSite = |
|
|
( siteId: number ) => |
|
|
async ( { dispatch }: Dispatch ) => { |
|
|
dispatch.fetchSite(); |
|
|
try { |
|
|
const existingSite: SiteDetails | undefined = await wpcomRequest( { |
|
|
path: '/sites/' + encodeURIComponent( siteId ), |
|
|
apiVersion: '1.1', |
|
|
query: 'force=wpcom', |
|
|
} ); |
|
|
dispatch.receiveSite( siteId, existingSite ); |
|
|
} catch ( err ) { |
|
|
dispatch.receiveSiteFailed( siteId, err as NewSiteErrorResponse ); |
|
|
} |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getSiteDomains = |
|
|
( siteId: number ) => |
|
|
async ( { dispatch }: Dispatch ) => { |
|
|
const result: { domains: Domain[] } = await wpcomRequest( { |
|
|
path: '/sites/' + encodeURIComponent( siteId ) + '/domains', |
|
|
apiVersion: '1.2', |
|
|
} ); |
|
|
dispatch.receiveSiteDomains( siteId, result?.domains ); |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getSiteSettings = |
|
|
( siteId: number ) => |
|
|
async ( { dispatch }: Dispatch ) => { |
|
|
const result: { settings: SiteSettings } = await wpcomRequest( { |
|
|
path: '/sites/' + encodeURIComponent( siteId ) + '/settings', |
|
|
apiVersion: '1.4', |
|
|
} ); |
|
|
|
|
|
dispatch.receiveSiteSettings( siteId, result?.settings ); |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getSiteTheme = |
|
|
( siteId: number ) => |
|
|
async ( { dispatch }: Dispatch ) => { |
|
|
const theme: CurrentTheme = await wpcomRequest( { |
|
|
path: '/sites/' + encodeURIComponent( siteId ) + '/themes/mine', |
|
|
apiVersion: '1.1', |
|
|
} ); |
|
|
|
|
|
dispatch.receiveSiteTheme( siteId, theme ); |
|
|
}; |
|
|
|