Skip to content

Commit

Permalink
feat(WebexAdaptiveCard): add onSubmit prop to notify when submit star…
Browse files Browse the repository at this point in the history
…ts and ends
  • Loading branch information
karinasigartau0798 authored and cipak committed Mar 21, 2022
1 parent a800592 commit bf68b7a
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/components/WebexAdaptiveCard/WebexAdaptiveCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,44 @@ import webexComponentClasses from '../helpers';
import {useAdaptiveCard} from '../hooks';
import AdaptiveCard from '../adaptive-cards/AdaptiveCard/AdaptiveCard';

/**
* Action to perform when submitting a card
*
* @callback submitCallback
* @param {object} inputs Data to submit
* @param {Promise<object>} submitPromise Promise that resolves to the submitted action
*/

/**
* WebexAdaptiveCard component displays a webex adaptive card.
*
* @param {object} props Data passed to the component
* @param {string} props.activityID ID of the activity corresponding to this card
* @param {string} [props.className] Custom CSS class to apply
* @param {submitCallback} [props.onSubmit] Action to perform when submitting a card
* @param {object} [props.style] Custom style to apply
* @returns {object} JSX of the component
*/
export default function WebexAdaptiveCard({activityID, className, style}) {
export default function WebexAdaptiveCard({
activityID,
className,
onSubmit,
style,
}) {
const [card, submit] = useAdaptiveCard(activityID);
const [cssClasses] = webexComponentClasses('adaptive-card', className);

const handleSubmit = (inputs) => {
const submitPromise = submit(inputs).toPromise();

onSubmit(submitPromise, inputs);
};

return (
<AdaptiveCard
className={cssClasses}
template={card}
onSubmit={(inputs) => submit(inputs).subscribe()}
onSubmit={handleSubmit}
style={style}
/>
);
Expand All @@ -32,9 +52,11 @@ WebexAdaptiveCard.propTypes = {
activityID: PropTypes.string.isRequired,
className: PropTypes.string,
style: PropTypes.shape(),
onSubmit: PropTypes.func,
};

WebexAdaptiveCard.defaultProps = {
className: undefined,
style: undefined,
onSubmit: () => {},
};

0 comments on commit bf68b7a

Please sign in to comment.