Skip to content

Commit

Permalink
feat(WebexAdaptiveCard): add submit status message
Browse files Browse the repository at this point in the history
  • Loading branch information
CoroDaniel authored and cipak committed Mar 24, 2022
1 parent 549ea14 commit 38c64a5
Show file tree
Hide file tree
Showing 11 changed files with 657 additions and 597 deletions.
1,136 changes: 570 additions & 566 deletions src/components/WebexActivity/__snapshots__/WebexActivity.stories.storyshot

Large diffs are not rendered by default.

45 changes: 37 additions & 8 deletions src/components/WebexAdaptiveCard/WebexAdaptiveCard.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import React, {useState} from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';

import webexComponentClasses from '../helpers';
import {useAdaptiveCard} from '../hooks';
Expand All @@ -19,44 +20,72 @@ import AdaptiveCard from '../adaptive-cards/AdaptiveCard/AdaptiveCard';
* @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 {string} [props.msgSubmitStarted] Message to display while submitting user input
* @param {string} [props.msgSubmitSuccess] Message to display when submit finished with success
* @param {string} [props.msgSubmitFail] Message to display when submit failed
* @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,
msgSubmitFail,
msgSubmitStarted,
msgSubmitSuccess,
onSubmit,
style,
}) {
const [card, submit] = useAdaptiveCard(activityID);
const [cssClasses] = webexComponentClasses('adaptive-card', className);
const [cssClasses, sc] = webexComponentClasses('adaptive-card', className);
const [submitStatus, setSubmitStatus] = useState({});

const handleSubmit = (inputs) => {
setSubmitStatus({message: msgSubmitStarted});
const submitPromise = submit(inputs).toPromise();

submitPromise.then(
() => setSubmitStatus({message: msgSubmitSuccess}),
() => setSubmitStatus({message: msgSubmitFail, isError: true}),
).finally(
setTimeout(() => setSubmitStatus({}), 2000),
);

onSubmit(submitPromise, inputs);
};

return (
<AdaptiveCard
<div
className={cssClasses}
template={card}
onSubmit={handleSubmit}
style={style}
/>
>
<AdaptiveCard
className={sc('card')}
template={card}
onSubmit={handleSubmit}
/>
{submitStatus.message && (
<div className={classnames(sc('status'), {[sc('status--error')]: submitStatus.isError})}>{submitStatus.message}</div>
)}
</div>
);
}

WebexAdaptiveCard.propTypes = {
activityID: PropTypes.string.isRequired,
className: PropTypes.string,
style: PropTypes.shape(),
msgSubmitFail: PropTypes.string,
msgSubmitStarted: PropTypes.string,
msgSubmitSuccess: PropTypes.string,
onSubmit: PropTypes.func,
style: PropTypes.shape(),
};

WebexAdaptiveCard.defaultProps = {
className: undefined,
style: undefined,
msgSubmitFail: 'Error',
msgSubmitStarted: 'Sending...',
msgSubmitSuccess: 'Sent',
onSubmit: () => {},
style: undefined,
};
26 changes: 26 additions & 0 deletions src/components/WebexAdaptiveCard/WebexAdaptiveCard.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
$C: #{$WEBEX_COMPONENTS_CLASS_PREFIX}-adaptive-card;

.#{$C} {
display: flex;
flex-direction: column;
align-items: stretch;

.#{$C}__card {
flex: 1;
}

.#{$C}__status {
display: flex;
font-size: 0.75rem;
margin-top: 0.25rem;
margin-bottom: 0.25rem;
padding-left: 1rem;
color: var(--wxc-adaptive-cards--color--light);

&--error {
color: var(--wxc-adaptive-cards--color--attention);
background-color: var(--wxc-adaptive-cards--background--attention);
border-radius: 0.5rem;
}
}
}
1 change: 1 addition & 0 deletions src/components/_components.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

@import 'WebexActivity/WebexActivity';
@import 'WebexActivityStream/WebexActivityStream';
@import 'WebexAdaptiveCard/WebexAdaptiveCard';
@import 'WebexAudioSettings/WebexAudioSettings';
@import 'WebexAvatar/WebexAvatar';
@import 'WebexInMeeting/WebexInMeeting';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import '../TextRun/TextRun';
function AdaptiveCardInternal({
action, data, className, inherited, style,
}) {
const [cssClasses] = webexComponentClasses('adaptive-card', [className, 'wxc-ac-container--has-padding']);
const [cssClasses] = webexComponentClasses('ac-adaptive-card', [className, 'wxc-ac-container--has-padding']);
let showFallbackText = false;

if (data.$schema && data.$schema !== 'http://adaptivecards.io/schemas/adaptive-card.json') {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.#{$WEBEX_COMPONENTS_CLASS_PREFIX}-adaptive-card {
.#{$WEBEX_COMPONENTS_CLASS_PREFIX}-ac-adaptive-card {
background: var(--wxc-primary-background);
color: var(--wxc-text-color);
overflow: auto;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`Storyshots Messaging/AdaptiveCard/Actions Action Execute 1`] = `
Array [
<div
className="wxc wxc-adaptive-card wxc wxc-ac wxc-ac-container--vertical wxc-ac-container--has-padding"
className="wxc wxc-ac-adaptive-card wxc wxc-ac wxc-ac-container--vertical wxc-ac-container--has-padding"
style={Object {}}
>
<div
Expand Down Expand Up @@ -195,7 +195,7 @@ Array [
exports[`Storyshots Messaging/AdaptiveCard/Actions Action Open URL 1`] = `
Array [
<div
className="wxc wxc-adaptive-card wxc wxc-ac wxc-ac-container--vertical wxc-ac-container--has-padding"
className="wxc wxc-ac-adaptive-card wxc wxc-ac wxc-ac-container--vertical wxc-ac-container--has-padding"
style={Object {}}
>
<div
Expand Down Expand Up @@ -337,7 +337,7 @@ Array [
exports[`Storyshots Messaging/AdaptiveCard/Actions Action Show Card 1`] = `
Array [
<div
className="wxc wxc-adaptive-card wxc wxc-ac wxc-ac-container--vertical wxc-ac-container--has-padding"
className="wxc wxc-ac-adaptive-card wxc wxc-ac wxc-ac-container--vertical wxc-ac-container--has-padding"
style={Object {}}
>
<div
Expand Down Expand Up @@ -464,7 +464,7 @@ Array [
exports[`Storyshots Messaging/AdaptiveCard/Actions Action Submit 1`] = `
Array [
<div
className="wxc wxc-adaptive-card wxc wxc-ac wxc-ac-container--vertical wxc-ac-container--has-padding"
className="wxc wxc-ac-adaptive-card wxc wxc-ac wxc-ac-container--vertical wxc-ac-container--has-padding"
style={Object {}}
>
<div
Expand Down Expand Up @@ -759,7 +759,7 @@ Array [
exports[`Storyshots Messaging/AdaptiveCard/Actions Action Toggle Visibility 1`] = `
Array [
<div
className="wxc wxc-adaptive-card wxc wxc-ac wxc-ac-container--vertical wxc-ac-container--has-padding"
className="wxc wxc-ac-adaptive-card wxc wxc-ac wxc-ac-container--vertical wxc-ac-container--has-padding"
style={Object {}}
>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`Storyshots Messaging/AdaptiveCard/CardElements Image 1`] = `
Array [
<div
className="wxc wxc-adaptive-card wxc wxc-ac wxc-ac-container--vertical wxc-ac-container--has-padding"
className="wxc wxc-ac-adaptive-card wxc wxc-ac wxc-ac-container--vertical wxc-ac-container--has-padding"
style={Object {}}
>
<div
Expand Down Expand Up @@ -106,7 +106,7 @@ Array [
exports[`Storyshots Messaging/AdaptiveCard/CardElements Rich Text Block 1`] = `
Array [
<div
className="wxc wxc-adaptive-card wxc wxc-ac wxc-ac-container--vertical wxc-ac-container--has-padding"
className="wxc wxc-ac-adaptive-card wxc wxc-ac wxc-ac-container--vertical wxc-ac-container--has-padding"
style={Object {}}
>
<div
Expand Down Expand Up @@ -334,7 +334,7 @@ Array [
exports[`Storyshots Messaging/AdaptiveCard/CardElements Text Block 1`] = `
Array [
<div
className="wxc wxc-adaptive-card wxc wxc-ac wxc-ac-container--vertical wxc-ac-container--has-padding"
className="wxc wxc-ac-adaptive-card wxc wxc-ac wxc-ac-container--vertical wxc-ac-container--has-padding"
style={Object {}}
>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`Storyshots Messaging/AdaptiveCard/Containers Action Set 1`] = `
Array [
<div
className="wxc wxc-adaptive-card wxc wxc-ac wxc-ac-container--vertical wxc-ac-container--has-padding"
className="wxc wxc-ac-adaptive-card wxc wxc-ac wxc-ac-container--vertical wxc-ac-container--has-padding"
style={Object {}}
>
<div
Expand Down Expand Up @@ -203,7 +203,7 @@ Array [
exports[`Storyshots Messaging/AdaptiveCard/Containers Column 1`] = `
Array [
<div
className="wxc wxc-adaptive-card wxc wxc-ac wxc-ac-container--vertical wxc-ac-container--has-padding"
className="wxc wxc-ac-adaptive-card wxc wxc-ac wxc-ac-container--vertical wxc-ac-container--has-padding"
style={Object {}}
>
<div
Expand Down Expand Up @@ -2706,7 +2706,7 @@ Array [
exports[`Storyshots Messaging/AdaptiveCard/Containers Column Set 1`] = `
Array [
<div
className="wxc wxc-adaptive-card wxc wxc-ac wxc-ac-container--vertical wxc-ac-container--has-padding"
className="wxc wxc-ac-adaptive-card wxc wxc-ac wxc-ac-container--vertical wxc-ac-container--has-padding"
style={Object {}}
>
<div
Expand Down Expand Up @@ -3153,7 +3153,7 @@ Array [
exports[`Storyshots Messaging/AdaptiveCard/Containers Container 1`] = `
Array [
<div
className="wxc wxc-adaptive-card wxc wxc-ac wxc-ac-container--vertical wxc-ac-container--has-padding"
className="wxc wxc-ac-adaptive-card wxc wxc-ac wxc-ac-container--vertical wxc-ac-container--has-padding"
style={Object {}}
>
<div
Expand Down Expand Up @@ -4054,7 +4054,7 @@ Array [
exports[`Storyshots Messaging/AdaptiveCard/Containers Fact Set 1`] = `
Array [
<div
className="wxc wxc-adaptive-card wxc wxc-ac wxc-ac-container--vertical wxc-ac-container--has-padding"
className="wxc wxc-ac-adaptive-card wxc wxc-ac wxc-ac-container--vertical wxc-ac-container--has-padding"
style={Object {}}
>
<div
Expand Down Expand Up @@ -4140,7 +4140,7 @@ Array [
exports[`Storyshots Messaging/AdaptiveCard/Containers Image Set 1`] = `
Array [
<div
className="wxc wxc-adaptive-card wxc wxc-ac wxc-ac-container--vertical wxc-ac-container--has-padding"
className="wxc wxc-ac-adaptive-card wxc wxc-ac wxc-ac-container--vertical wxc-ac-container--has-padding"
style={Object {}}
>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`Storyshots Messaging/AdaptiveCard/Inputs Input Choice Set 1`] = `
Array [
<div
className="wxc wxc-adaptive-card wxc wxc-ac wxc-ac-container--vertical wxc-ac-container--has-padding"
className="wxc wxc-ac-adaptive-card wxc wxc-ac wxc-ac-container--vertical wxc-ac-container--has-padding"
style={Object {}}
>
<div
Expand Down Expand Up @@ -533,7 +533,7 @@ Array [
exports[`Storyshots Messaging/AdaptiveCard/Inputs Input Date 1`] = `
Array [
<div
className="wxc wxc-adaptive-card wxc wxc-ac wxc-ac-container--vertical wxc-ac-container--has-padding"
className="wxc wxc-ac-adaptive-card wxc wxc-ac wxc-ac-container--vertical wxc-ac-container--has-padding"
style={Object {}}
>
<div
Expand Down Expand Up @@ -653,7 +653,7 @@ Array [
exports[`Storyshots Messaging/AdaptiveCard/Inputs Input Number 1`] = `
Array [
<div
className="wxc wxc-adaptive-card wxc wxc-ac wxc-ac-container--vertical wxc-ac-container--has-padding"
className="wxc wxc-ac-adaptive-card wxc wxc-ac wxc-ac-container--vertical wxc-ac-container--has-padding"
style={Object {}}
>
<div
Expand Down Expand Up @@ -856,7 +856,7 @@ Array [
exports[`Storyshots Messaging/AdaptiveCard/Inputs Input Text 1`] = `
Array [
<div
className="wxc wxc-adaptive-card wxc wxc-ac wxc-ac-container--vertical wxc-ac-container--has-padding"
className="wxc wxc-ac-adaptive-card wxc wxc-ac wxc-ac-container--vertical wxc-ac-container--has-padding"
style={Object {}}
>
<div
Expand Down Expand Up @@ -1315,7 +1315,7 @@ Array [
exports[`Storyshots Messaging/AdaptiveCard/Inputs Input Time 1`] = `
Array [
<div
className="wxc wxc-adaptive-card wxc wxc-ac wxc-ac-container--vertical wxc-ac-container--has-padding"
className="wxc wxc-ac-adaptive-card wxc wxc-ac wxc-ac-container--vertical wxc-ac-container--has-padding"
style={Object {}}
>
<div
Expand Down Expand Up @@ -1516,7 +1516,7 @@ Array [
exports[`Storyshots Messaging/AdaptiveCard/Inputs Input Toggle 1`] = `
Array [
<div
className="wxc wxc-adaptive-card wxc wxc-ac wxc-ac-container--vertical wxc-ac-container--has-padding"
className="wxc wxc-ac-adaptive-card wxc wxc-ac wxc-ac-container--vertical wxc-ac-container--has-padding"
style={Object {}}
>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`Storyshots Messaging/AdaptiveCard Card 1`] = `
Array [
<div
className="wxc wxc-adaptive-card wxc wxc-ac wxc-ac-container--vertical wxc-ac-container--has-padding"
className="wxc wxc-ac-adaptive-card wxc wxc-ac wxc-ac-container--vertical wxc-ac-container--has-padding"
style={Object {}}
>
<div
Expand Down

0 comments on commit 38c64a5

Please sign in to comment.