Ensure feedback options are not submitting in their translated forms.

Этот коммит содержится в:
Conor Macpherson
2023-04-04 15:39:18 -04:00
родитель 8afb6a6b39
Коммит 23d873cda3
2 изменённых файлов: 45 добавлений и 27 удалений

Просмотреть файл

@@ -6,7 +6,7 @@ import React from 'react';
import {injectIntl, WrappedComponentProps} from 'react-intl'; import {injectIntl, WrappedComponentProps} from 'react-intl';
import {Feedback} from '@mattermost/types/cloud'; import {Feedback} from '@mattermost/types/cloud';
import FeedbackModal from 'components/feedback_modal/feedback'; import FeedbackModal, {FeedbackOption} from 'components/feedback_modal/feedback';
type Props = { type Props = {
onSubmit: (deleteFeedback: Feedback) => void; onSubmit: (deleteFeedback: Feedback) => void;
@@ -28,23 +28,35 @@ const DeleteFeedbackModal = (props: Props) => {
defaultMessage: 'Delete Workspace', defaultMessage: 'Delete Workspace',
}); });
const deleteFeedbackOptions = [ const deleteFeedbackOptions: FeedbackOption[] = [
props.intl.formatMessage({ {
id: 'feedback.deleteWorkspace.feedbackNoValue', translatedMessage: props.intl.formatMessage({
defaultMessage: 'No longer found value', id: 'feedback.deleteWorkspace.feedbackNoValue',
}), defaultMessage: 'No longer found value',
props.intl.formatMessage({ }),
id: 'feedback.deleteWorkspace.feedbackMoving', submissionValue: 'No longer found value',
defaultMessage: 'Moving to a different solution', },
}), {
props.intl.formatMessage({ translatedMessage: props.intl.formatMessage({
id: 'feedback.deleteWorkspace.feedbackMistake', id: 'feedback.deleteWorkspace.feedbackMoving',
defaultMessage: 'Created a workspace by mistake', defaultMessage: 'Moving to a different solution',
}), }),
props.intl.formatMessage({ submissionValue: 'Moving to a different solution',
id: 'feedback.deleteWorkspace.feedbackHosting', },
defaultMessage: 'Moving to hosting my own Mattermost instance (self-hosted)', {
}), translatedMessage: props.intl.formatMessage({
id: 'feedback.deleteWorkspace.feedbackMistake',
defaultMessage: 'Created a workspace by mistake',
}),
submissionValue: 'Created a workspace by mistake',
},
{
translatedMessage: props.intl.formatMessage({
id: 'feedback.deleteWorkspace.feedbackHosting',
defaultMessage: 'Moving to hosting my own Mattermost instance (self-hosted)',
}),
submissionValue: 'Moving to hosting my own Mattermost instance (self-hosted)',
}
]; ];
return ( return (

Просмотреть файл

@@ -14,19 +14,25 @@ import RadioButtonGroup from 'components/common/radio_group';
import {ModalIdentifiers} from 'utils/constants'; import {ModalIdentifiers} from 'utils/constants';
import './feedback.scss'; import './feedback.scss';
import {string} from 'yargs';
export interface FeedbackOption {
translatedMessage: string;
submissionValue: string;
};
type Props = { type Props = {
onSubmit: (deleteFeedback: Feedback) => void; onSubmit: (deleteFeedback: Feedback) => void;
title: string; title: string;
submitText: string; submitText: string;
feedbackOptions: string[]; feedbackOptions: FeedbackOption[];
freeformTextPlaceholder: string; freeformTextPlaceholder: string;
} & WrappedComponentProps } & WrappedComponentProps
function FeedbackModal(props: Props) { function FeedbackModal(props: Props) {
const maxFreeFormTextLength = 500; const maxFreeFormTextLength = 500;
const optionOther = props.intl.formatMessage({id: 'feedback.other', defaultMessage: 'Other'}); const optionOther = {translatedMessage: props.intl.formatMessage({id: 'feedback.other', defaultMessage: 'Other'}), submissionValue: 'Other'};
const feedbackModalOptions: string[] = [ const feedbackModalOptions: FeedbackOption[] = [
...props.feedbackOptions, ...props.feedbackOptions,
optionOther, optionOther,
]; ];
@@ -34,9 +40,9 @@ function FeedbackModal(props: Props) {
const [reason, setReason] = useState(''); const [reason, setReason] = useState('');
const [comments, setComments] = useState(''); const [comments, setComments] = useState('');
const reasonNotSelected = reason === ''; const reasonNotSelected = reason === '';
const reasonOther = reason === optionOther; const reasonOther = reason === optionOther.submissionValue;
const commentsNotProvided = comments.trim() === ''; const commentsNotProvided = comments.trim() === '';
const submitDisabled = reasonNotSelected || (reason === optionOther && commentsNotProvided); const submitDisabled = reasonNotSelected || (reasonOther && commentsNotProvided);
const dispatch = useDispatch(); const dispatch = useDispatch();
@@ -71,15 +77,15 @@ function FeedbackModal(props: Props) {
testId='FeedbackModalRadioGroup' testId='FeedbackModalRadioGroup'
values={feedbackModalOptions.map((option) => { values={feedbackModalOptions.map((option) => {
return { return {
value: option, value: option.submissionValue,
key: option, key: option.translatedMessage,
testId: option, testId: option.submissionValue,
}; };
})} })}
value={reason} value={reason}
onChange={(e) => setReason(e.target.value)} onChange={(e) => setReason(e.target.value)}
/> />
{reason === optionOther && {reasonOther &&
<> <>
<textarea <textarea
data-testid={'FeedbackModal__TextInput'} data-testid={'FeedbackModal__TextInput'}