Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
validate(value: string) {
if (!value) {
throw new Error(
T.phrase(
'This field is required.',
{},
{
context: 'Generic error when a form field is required',
key: 'lunar.form.fieldRequired',
},
),
);
}
}
))}
<textarea k="lunar.feedback.moreMessage" label="{" name="feedback"> }
placeholder={
data.type === 'bug'
? T.phrase(
'What happened? Sharing steps to reproduce the problem you experienced can be helpful.',
{},
{
context:
'Default description in the feedback form when submitting a bug report',
key: 'lunar.feedback.moreBug',
},
)
: T.phrase(
'Share your experience with us. What went well? What could have gone better?',
{},
{
context:
'Default description in the feedback form when submitting general feedback',
key: 'lunar.feedback.moreFeedback',
},</textarea>
private handleValidate = throttleToSinglePromise(async (data: object) => {
const nextData = data as Data;
const errors = await this.validate(nextData);
const passes = this.props.onValidate!(nextData, errors, this.getFields());
let errorCount = Object.keys(errors).length;
if (!passes && errorCount === 0) {
errors[FORM_ERROR] = T.phrase(
'Failed to validate form. Please try again.',
{},
{
context: 'A generic error when a form failed validation in any way',
key: 'lunar.form.validateFailed',
},
);
errorCount += 1;
}
if (errorCount > 0) {
this.props.onFailedValidate!(nextData, errors);
}
return errors;
});
return promise.catch(error => {
if (setErrors) {
setErrors({
[FORM_ERROR]: T.phrase(
'Failed to submit form. %{error}',
{
error: getErrorMessage(error),
},
{
context: 'A generic error when a form failed to submit',
key: 'lunar.form.submitFailed',
},
),
});
}
this.props.onFailedSubmit!(preparedData, error);
throw error;
});
phrase="Tell us a little bit more"
context="Feedback form"
/>
}
placeholder={
data.type === 'bug'
? T.phrase(
'What happened? Sharing steps to reproduce the problem you experienced can be helpful.',
{},
{
context:
'Default description in the feedback form when submitting a bug report',
key: 'lunar.feedback.moreBug',
},
)
: T.phrase(
'Share your experience with us. What went well? What could have gone better?',
{},
{
context:
'Default description in the feedback form when submitting general feedback',
key: 'lunar.feedback.moreFeedback',
},
)
}
validator={this.validate}
/>
/>
)}
)}
<select k="lunar.feedback.featureMessage" label="{" name="category">
}
placeholder={T.phrase(
'Select a feature',
{},
{
context: 'Selecting a feature within the feedback form',
key: 'lunar.feedback.selectFeature',
},
)}
validator={this.validate}
>
{Object.entries(categories).map(([key, label]) => (
<option value="{key}">
{label}
</option>
))}
</select>