-
Notifications
You must be signed in to change notification settings - Fork 4
fix: sponsor form default values and some style changes #839
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -211,6 +211,7 @@ | |
| "testEnvironment": "jsdom", | ||
| "setupFilesAfterEnv": [ | ||
| "<rootDir>/testSetupFile.js" | ||
| ] | ||
| ], | ||
| "maxWorkers": 4 | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,58 @@ | ||||||||||||||||||
| import React from "react"; | ||||||||||||||||||
| import PropTypes from "prop-types"; | ||||||||||||||||||
| import T from "i18n-react/dist/i18n-react"; | ||||||||||||||||||
| import { | ||||||||||||||||||
| Select, | ||||||||||||||||||
| FormHelperText, | ||||||||||||||||||
| FormControl, | ||||||||||||||||||
| MenuItem, | ||||||||||||||||||
| InputLabel | ||||||||||||||||||
| } from "@mui/material"; | ||||||||||||||||||
| import { useField } from "formik"; | ||||||||||||||||||
|
|
||||||||||||||||||
| const MuiFormikSelectV2 = ({ name, label, placeholder, options, ...rest }) => { | ||||||||||||||||||
| const [field, meta] = useField(name); | ||||||||||||||||||
| const finalPlaceholder = | ||||||||||||||||||
| placeholder || T.translate("general.select_an_option"); | ||||||||||||||||||
|
|
||||||||||||||||||
| return ( | ||||||||||||||||||
| <FormControl fullWidth error={meta.touched && Boolean(meta.error)}> | ||||||||||||||||||
| {label && <InputLabel id={`${name}-label`}>{label}</InputLabel>} | ||||||||||||||||||
| <Select | ||||||||||||||||||
| name={name} | ||||||||||||||||||
| label={label} | ||||||||||||||||||
| labelId={`${name}-label`} | ||||||||||||||||||
| displayEmpty | ||||||||||||||||||
| // eslint-disable-next-line react/jsx-props-no-spreading | ||||||||||||||||||
| {...field} | ||||||||||||||||||
| // eslint-disable-next-line react/jsx-props-no-spreading | ||||||||||||||||||
| {...rest} | ||||||||||||||||||
| renderValue={(selected) => { | ||||||||||||||||||
| if (!selected) { | ||||||||||||||||||
| return <em>{finalPlaceholder}</em>; | ||||||||||||||||||
| } | ||||||||||||||||||
|
Comment on lines
+30
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Falsy value check may incorrectly show placeholder for valid selections. The condition 🐛 Suggested fix: use explicit null/undefined check renderValue={(selected) => {
- if (!selected) {
+ if (selected === null || selected === undefined) {
return <em>{finalPlaceholder}</em>;
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||
| const selectedOption = options.find( | ||||||||||||||||||
| ({ value }) => value === selected | ||||||||||||||||||
| ); | ||||||||||||||||||
| return selectedOption ? selectedOption.label : ""; | ||||||||||||||||||
| }} | ||||||||||||||||||
| > | ||||||||||||||||||
| {options.map((op) => ( | ||||||||||||||||||
| <MenuItem key={`selectop-${op.value}`} value={op.value}> | ||||||||||||||||||
| {op.label} | ||||||||||||||||||
| </MenuItem> | ||||||||||||||||||
| ))} | ||||||||||||||||||
| </Select> | ||||||||||||||||||
| {meta.touched && meta.error && ( | ||||||||||||||||||
| <FormHelperText>{meta.error}</FormHelperText> | ||||||||||||||||||
| )} | ||||||||||||||||||
| </FormControl> | ||||||||||||||||||
| ); | ||||||||||||||||||
| }; | ||||||||||||||||||
|
|
||||||||||||||||||
| MuiFormikSelectV2.propTypes = { | ||||||||||||||||||
| name: PropTypes.string.isRequired, | ||||||||||||||||||
| options: PropTypes.array.isRequired | ||||||||||||||||||
| }; | ||||||||||||||||||
|
|
||||||||||||||||||
| export default MuiFormikSelectV2; | ||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -34,16 +34,20 @@ const parseValue = (item, timeZone) => { | |||||||||||||||||||||
| return item.current_value | ||||||||||||||||||||||
| ? parseInt(item.current_value) | ||||||||||||||||||||||
| : item.minimum_quantity || 0; | ||||||||||||||||||||||
| case "ComboBox": | ||||||||||||||||||||||
| case "RadioButtonList": | ||||||||||||||||||||||
| case "ComboBox": { | ||||||||||||||||||||||
| const defaultVal = item.values.find((v) => v.is_default)?.id; | ||||||||||||||||||||||
| return item.current_value || defaultVal || ""; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| case "CheckBoxList": { | ||||||||||||||||||||||
| const defaultVal = item.values.find((v) => v.is_default)?.id; | ||||||||||||||||||||||
| return item.current_value || (defaultVal ? [defaultVal] : []); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
Comment on lines
+42
to
+45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep
🐛 Suggested fix case "CheckBoxList": {
- const defaultVal = item.values.find((v) => v.is_default)?.id;
- return item.current_value || defaultVal || [];
+ if (Array.isArray(item.current_value)) return item.current_value;
+ return (
+ item.values?.filter((v) => v.is_default)?.map((v) => v.id) || []
+ );
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||
| case "Text": | ||||||||||||||||||||||
| case "TextArea": | ||||||||||||||||||||||
| return item.current_value || ""; | ||||||||||||||||||||||
| case "CheckBox": | ||||||||||||||||||||||
| return item.current_value ? item.current_value === "True" : false; | ||||||||||||||||||||||
| case "CheckBoxList": | ||||||||||||||||||||||
| return item.current_value || []; | ||||||||||||||||||||||
| case "RadioButtonList": | ||||||||||||||||||||||
| return item.current_value || ""; | ||||||||||||||||||||||
| case "Time": | ||||||||||||||||||||||
| return item.current_value | ||||||||||||||||||||||
| ? moment.tz(item.current_value, "HH:mm", timeZone) | ||||||||||||||||||||||
|
|
@@ -152,12 +156,10 @@ const buildInitialValues = (form, timeZone) => { | |||||||||||||||||||||
|
|
||||||||||||||||||||||
| const buildValidationSchema = (items) => { | ||||||||||||||||||||||
| const schema = items.reduce((acc, item) => { | ||||||||||||||||||||||
| item.meta_fields | ||||||||||||||||||||||
| .filter((f) => f.class_field === "Form") | ||||||||||||||||||||||
| .map((f) => { | ||||||||||||||||||||||
| acc[`i-${item.form_item_id}-c-${f.class_field}-f-${f.type_id}`] = | ||||||||||||||||||||||
| getYupValidation(f); | ||||||||||||||||||||||
| }); | ||||||||||||||||||||||
| item.meta_fields.map((f) => { | ||||||||||||||||||||||
| acc[`i-${item.form_item_id}-c-${f.class_field}-f-${f.type_id}`] = | ||||||||||||||||||||||
| getYupValidation(f); | ||||||||||||||||||||||
| }); | ||||||||||||||||||||||
| // notes | ||||||||||||||||||||||
| acc[`i-${item.form_item_id}-c-global-f-notes`] = yup.string( | ||||||||||||||||||||||
| T.translate("validation.string") | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing
shrinkprop on InputLabel causes label overlap with placeholder.When using
displayEmptyon Select, theInputLabelshould haveshrinkprop to prevent the label from overlapping the placeholder text. TheMuiFormikDropdownCheckboxcomponent correctly usesshrinkbut this component doesn't.🐛 Suggested fix
📝 Committable suggestion
🤖 Prompt for AI Agents