Skip to content

Commit

Permalink
feat(modal): added global modal to render in web-dir from client apps…
Browse files Browse the repository at this point in the history
… includes api and message code
  • Loading branch information
S-Dingley-Genesys committed Jul 1, 2021
1 parent f597152 commit 9eb63a7
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
20 changes: 20 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ export interface ClientConfigOptions {
hostOrigin?: string;
}

export const modalTypes = {
WEM_COACHING_UI: 'wemCoachingUi'
};

/**
* This class is the primary interface that an embedded iframe client should use to communicate with
* the host application.
Expand Down Expand Up @@ -420,6 +424,22 @@ bad input into one of the iframe-coordinator client methods.
});
}

/**
* Asks the host application to launch an instance of a global modal
*
* Currently the only available one is WEM Coaching UI
*
* @param modalType the type of modal to be used.
* @param modalData any data you wish to be sent to the modal, Conversation IDs etc.
*
*/
public requestModal(modalType: any, modalData: any) {
this._sendToHost({
msgType: 'modalRequest',
msg: { modalType, modalData }
});
}

/**
* Asks the host application to display a user notification.
*
Expand Down
7 changes: 5 additions & 2 deletions src/messages/ClientToHost.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { dispatch, guard } from 'decoders';
import { decoder as keyDownDecoder, LabeledKeyDown } from './KeyDown';
import { LabeledStarted, startedDecoder } from './Lifecycle';
import { decoder as modalDecoder, LabeledModal } from './Modal';
import { decoder as navRequestDecoder, LabeledNavRequest } from './NavRequest';
import { decoder as notifyDecoder, LabeledNotification } from './Notification';
import {
Expand All @@ -17,7 +18,8 @@ export type ClientToHost =
| LabeledNotification
| LabeledNavRequest
| LabeledStarted
| LabeledKeyDown;
| LabeledKeyDown
| LabeledModal;

/**
* Validates correctness of messages being sent from
Expand All @@ -32,7 +34,8 @@ export function validate(msg: any): ClientToHost {
client_started: startedDecoder,
navRequest: navRequestDecoder,
notifyRequest: notifyDecoder,
toastRequest: notifyDecoder
toastRequest: notifyDecoder,
modalRequest: modalDecoder
})
)(msg);
}
18 changes: 18 additions & 0 deletions src/messages/Modal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { constant, Decoder, mixed } from 'decoders';
import { labeledDecoder, LabeledMsg } from './LabeledMsg';

/**
* A message used to publish a generic messages
* between the clients and the host application.
*/
export interface LabeledModal extends LabeledMsg<'modalRequest', any> {
/** Message identifier */
msgType: 'modalRequest';
}

const decoder: Decoder<LabeledModal> = labeledDecoder(
constant<'modalRequest'>('modalRequest'),
mixed
);

export { decoder };

0 comments on commit 9eb63a7

Please sign in to comment.