This library is the best way for your company to embed PerfectGym's Client Portal on your site. It provides a range of features which covers intergration needs:
- Navigating from your site.
- Showing loader on data load.
- Callbacks on user log in/out.
- Callbacks on changing states.
- Cookies support on safari.
- Has TypeScript support.
Embedded Client Portal has transparent background, basic branding looks best on grey/blurred image background. To maintain best responsiveness it is recommended to set your Embedded Client Portal width to full page width.
We recommend including ClientPortal.Embed and iframe-resizer using jsDelivr CDN.
- Add ClientPortal.Embed styling.
At the end of <head>
add:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@perfectgym/client-portal@latest/dist/ClientPortal.css"></link>
- Add iframe-resizer GitHub page and ClientPortal.Embed GitHub page libraries.
At the end of <body>
tag add:
<script src="https://cdn.jsdelivr.net/npm/iframe-resizer/js/iframeResizer.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@perfectgym/client-portal@latest/dist/ClientPortal.min.js"></script>
- Initialize library.
After scripts form 2nd point add:
<script>
window.onload = function () {
var ClientPortal = window.PerfectGym.ClientPortal;
// element to which ClientPortal will be appended
var clientPortalElement = document.getElementById('pg-client-portal');
var options = {
url: "CLIENT_PORTAL_URL"
}
var embeddedClientPortal = new ClientPortal(clientPortalElement, options);
}
</script>
- Reload your page
Click here to play with live demo.
Package can be installed via NPM.
npm install @perfectgym/client-portal
It requires iframe-resizer as dependency.
import ClientPortal from "@perfectgym/client-portal";
// element to which ClientPortal will be appended
var clientPortalElement = document.getElementById('pg-client-portal');
var options = {
url: "CLIENT_PORTAL_URL"
}
var embeddedClientPortal = new ClientPortal(clientPortalElement, options);
API section covers:
- Constructor options Core Options
- Methods
- Data types
Options object must be passed passed to new ClientPortal constructor. url
parameter is required. The rest are optional.
var options = {
url: "CLIENT_PORTAL_URL"
}
new ClientPortal(clientPortalElement, options);
- type: string
Client Portal application url without fragment(the part before #). If Client Portal is hosted on PerfectGym domain correct url looks like: https://CLUB_NAME.perfectgym.pl/ClientPortal2/
.
- type: string
Url to Client Portal application. It will be loaded regarding url
, defaultState
or defaultStateParams
as the first page that user sees on the embedded Client Portal. It's main functionality is to give simple way of displaying calendar with predefined filters on your page. Example forceUrl
value looks like: https://CLUB_NAME.perfectgym.pl/ClientPortal2/#/Classes/1/Calendar?timeTableId=12&trainerId=92
. Domain from this option must match domain in url
option.
- type: ClientPortal.State
- default: ClientPortal.State.Profile
First state showed to user after load. Unauthenticated users are redirected to ClientPortal.State.Login.
- type: Object
- default: undefined
State params from with which Client Portal will be loaded.
- type: string // Language code standardized by ISO 639-1
If language
option is not set Client Portal tries to use user's browser language. If browser language is not supported by Club's Client Portal then language is set to default Client Portal language.
For list of available languages in your company please contact PerfectGym support.
- type: number
Client Portal min height in pixels.
- type: function()
Callback fired when iframe connects to Client Portal.
- type: function(authInfo: ClientPortalAuthInfo)
Callback fires when user logs in to Client Portal.
- type: function(authInfo: ClientPortalAuthInfo)
Callback fires when user logs out from Client Portal.
- type: function(stateInfo: ClientPortalChangeStateInfo)
Callback fires on state (view) change.
- type: function(scrollTop: number)
This function is used to override default library scroll behaviour. scrollTop
is scroll value which normally would be used to scroll parent page window.
- type: number
Used to adjust scroll behaviour.
If you have floating navigation which isn't pinned when page is scrolled to top and you have a bug in which field to which page is scrolled on validation error is hidden under floating navigation. Then topOffset
property should have passed navigation height (as a number).
- type: number
Used to apply a specific branding theme.
* type: boolean
* default: false
Hides "Book now" button on calendar when user is not logged. This function is useful when you want to embed only calendar on your site.
* type: boolean
* default: false
Disables a possibility to enroll for a course from within an embedded ClientPortal.
var options = {
url: "CLIENT_PORTAL_URL",
loginPage: {
navbar: true,
logo: true
}
}
var embeddedClientPortal = new ClientPortal(clientPortalElement, options);
Object helpful in customizing login page.
* type: boolean
* default: true
Show header.
* type: boolean
* default: true
Show logo in header.
var options = {
url: "CLIENT_PORTAL_URL",
navigation: {
hide: false,
logo: true
}
}
var embeddedClientPortal = new ClientPortal(clientPortalElement, options);
Options responsible for customizing navigation visible after user logs in.
* type: boolean
* default: false
Show navbar.
* type: boolean
* default: true
var options = {
url: "CLIENT_PORTAL_URL",
registration: {
logo: true
}
}
var embeddedClientPortal = new ClientPortal(clientPortalElement, options);
Options responsible for customizing registration.
* type: boolean
* default: true
var options = {
url: "CLIENT_PORTAL_URL",
loadMask: {
disable: true,
onShow: () => { console.log('show my load mask')},
onHide: () => { console.log('hide my load mask')}
}
}
var embeddedClientPortal = new ClientPortal(clientPortalElement, options);
Options responsible for customizing load mask.
- type: boolean
- default: false
Decides whether to show default Client Portal load mask. Load mask shows when Client Portal is requesting server data or on view change.
If changed to true you should use onShow()
and onHide()
options to show load mask on your site preventing user from making actions in ClientPortal.
- type: boolean
- default: false
Decides whether to hide load mask on initializing iframe.
- type: function()
Callback fired when Client Portal normally shows load mask.
- type: function()
Callback fired when Client Portal normally hides load mask.
var options = {
url: "CLIENT_PORTAL_URL",
modal: {
disableOverlay: false
}
}
var embeddedClientPortal = new ClientPortal(clientPortalElement, options);
- type: boolean
- default: false
Decides whether to show modal overlay layer on top and bottom of the iframe.
Overlay covers elements outside of iframe on parent element to focus user attention on popups and other elements opened in Client Portal.
If set to false dark overlay will be used only on elements inside modal.
If you would like to use your own overlay use onShow()
and onHide()
callback options.
- type: function()
Callback when Client Portal shows modal (popup).
- type: function()
Callback fires when Client Portal hides modal (popup).
- type: function()
Some dropdowns opens only on mobile mode. This callback fires when fullscreen dropdown opens on mobile mode.
- type: function()
Callback fires when dropdown opened only on mobile mode closes.
Methods can be used on embedded Client Portal object. All methods returns promise which is resolved on response from server.
- type: function(state: ClientPortal.State)
- returns: Promise<>
Navigates through ClientPortal. States are held in
ClientPortal.State
object.
Usage:
var CP = new ClientPortal(element, options)
CP.goTo(ClientPortal.State.Login)
- type: function(state: ClientPortal.State)
- returns: Promise<>
Logouts user.
- type: function(languageCode: string)
- returns: Promise<>
Changes client portal language.
Language code is a two letters string standardized by ISO 639-1.
- type: function()
- returns: Promise<authInfo: ClientPortalAuthInfo>
Returns info if user is authenticated.
- type: function()
- returns: Promise<element: HTMLIFrameElement>
Returns iframe element.
Types listed below are used as return types or parameters in options and methods.
Can be used in implementing own navigation, using goTo() method.
CP.goTo(ClientPortal.State.<STATE_FROM_LIST_BELOW>)
- Login
- Registration
- ClassesCalendar
- ClassesList
- PersonalTraining
- ReservedClasses
- Products
- BuyProducts
- ProfileEdit
- ProfileContract
- ProfileFreeze
- ProfilePrepaid
- ProfileChangePassword
- ProfilePayments
- ProfileFamily
{
isAuthenticated: boolean,
user: ClientPortalUserInfo
}
{
FirstName: string,
LastName: string,
Email: string,
HomeClubId: number,
PhotoUrl: string,
Type: string
}
{
fromState: ClientPortalStateInfo,
toState: ClientPortalStateInfo,
isVirtual: boolean
}
{
auth: boolean,
name: string,
params: Object //depends on current view
}