Skip to content
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

Clear Release Code Number when Release Code Type is NONE_OPTION #467

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import { useFormikContext } from "formik";
import { Box, Link, Stack } from "@mui/material";
import { scrollToError, useWindowDimensions } from "@newm-web/utils";
import {
Button,
CopyrightInputField,
DropdownSelectField,
HorizontalLine,
SwitchInputField,
TextInputField,
} from "@newm-web/elements";
import { Button, HorizontalLine } from "@newm-web/elements";
import theme from "@newm-web/theme";
import {
UploadSongRequest,
Expand Down Expand Up @@ -52,6 +53,12 @@ const AdvancedSongDetails = () => {
.toISOString()
.split("T")[0];

useEffect(() => {
if (values.barcodeType === NONE_OPTION || values.barcodeType === "") {
setFieldValue("barcodeNumber", "");
}
}, [setFieldValue, values.barcodeType]);

scandycuz marked this conversation as resolved.
Show resolved Hide resolved
useEffect(() => {
scrollToError(errors, isSubmitting, [
{
Expand Down
41 changes: 9 additions & 32 deletions packages/elements/src/lib/DropdownSelect.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,26 @@
import {
FocusEvent,
ForwardRefRenderFunction,
ForwardedRef,
HTMLProps,
KeyboardEvent,
MouseEventHandler,
SyntheticEvent,
forwardRef,
} from "react";
import { useAutocomplete } from "@mui/base/useAutocomplete";
import ArrowDropDownIcon from "@mui/icons-material/ArrowDropDown";
import theme from "@newm-web/theme";
import { Box } from "@mui/material";
import { WidthType } from "@newm-web/utils";
import TextInput from "./TextInput";
import ResultsList from "./styled/ResultsList";
import NoResultsText from "./styled/NoResultsText";
import { DropdownSelectFieldProps } from "./form/DropdownSelectField";

export interface DropdownSelectProps
extends Omit<HTMLProps<HTMLInputElement>, "as" | "ref"> {
readonly disabled?: boolean;
interface DropdownSelectProps extends DropdownSelectFieldProps {
readonly errorMessage?: string;
readonly handleBlur?: (event: FocusEvent<HTMLInputElement, Element>) => void;
readonly handleChange?: (newValue: string) => void;
readonly isOptional?: boolean;
readonly label?: string;
readonly name: string;
readonly noResultsText?: string;
readonly options: ReadonlyArray<string>;
readonly placeholder?: string;
readonly tags?: ReadonlyArray<string>;
readonly tooltipText?: string;
readonly widthType?: WidthType;
readonly onChange?: (
event: SyntheticEvent<Element, Event>,
newValue: string
) => void;
}

const DropdownSelect: ForwardRefRenderFunction<
Expand All @@ -40,8 +30,7 @@ const DropdownSelect: ForwardRefRenderFunction<
{
disabled,
errorMessage,
handleChange,
handleBlur,
onChange,
label,
name,
noResultsText = "Nothing found",
Expand All @@ -65,17 +54,14 @@ const DropdownSelect: ForwardRefRenderFunction<
} = useAutocomplete({
clearOnBlur: true,
getOptionLabel: (option) => option,

id: name,

// Removes warning for empty string not being a valid option
isOptionEqualToValue: (option, value) =>
value === "" ? true : option === value,
onChange: (event, newValue) => {
// Updates as empty string instead of invalid null error for empty field
// or for partial edit of selected input causing invalid undefined error
if (newValue === null || newValue === undefined) handleChange?.("");
else handleChange?.(newValue as string);
onChange?.(event, newValue ?? "");
},
options,
value: value as string,
Expand All @@ -95,14 +81,6 @@ const DropdownSelect: ForwardRefRenderFunction<
if (event.key === "Enter" && inputValue !== value) event.preventDefault();
};

/**
* Consolidates onBlur events for Formik Field and MUI's useAutocomplete.
*/
const handleBlurEvents = (event: FocusEvent<HTMLInputElement, Element>) => {
handleBlur?.(event);
inputProps.onBlur?.(event);
};

return (
<Box
sx={ {
Expand Down Expand Up @@ -133,7 +111,6 @@ const DropdownSelect: ForwardRefRenderFunction<
label={ label }
name={ name }
placeholder={ placeholder }
onBlur={ handleBlurEvents }
onKeyDown={ preventFormSubmit }
/>
</div>
Expand Down
4 changes: 2 additions & 2 deletions packages/elements/src/lib/form/DropdownMultiSelectField.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ForwardRefRenderFunction, SyntheticEvent, forwardRef } from "react";
import { Field, FieldProps } from "formik";
import { DropdownSelectFieldProps } from "./DropdownSelectField";
import DropdownMultiSelect from "../DropdownMultiSelect";
import { DropdownSelectProps } from "../DropdownSelect";

const DropdownMultiSelectField: ForwardRefRenderFunction<
HTMLInputElement,
DropdownSelectProps
DropdownSelectFieldProps
> = (props, ref) => (
<Field name={ props.name }>
{ ({ field, form, meta }: FieldProps) => (
Expand Down
51 changes: 34 additions & 17 deletions packages/elements/src/lib/form/DropdownSelectField.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,40 @@
import { ForwardRefRenderFunction, forwardRef } from "react";
import { ForwardRefRenderFunction, HTMLProps, forwardRef } from "react";
import { Field, FieldProps } from "formik";
import DropdownSelect, { DropdownSelectProps } from "../DropdownSelect";
import { WidthType } from "@newm-web/utils";
import DropdownSelect from "../DropdownSelect";

export interface DropdownSelectFieldProps
extends Omit<HTMLProps<HTMLInputElement>, "as" | "ref" | "onChange"> {
readonly disabled?: boolean;
readonly isOptional?: boolean;
readonly label?: string;
readonly name: string;
readonly noResultsText?: string;
readonly options: ReadonlyArray<string>;
readonly placeholder?: string;
readonly tooltipText?: string;
readonly widthType?: WidthType;
}

const DropdownSelectField: ForwardRefRenderFunction<
HTMLInputElement,
DropdownSelectProps
> = (props, ref) => (
<Field name={ props.name }>
{ ({ field, form, meta }: FieldProps) => (
<DropdownSelect
{ ...field }
{ ...props }
errorMessage={ meta.touched ? meta.error : "" }
handleBlur={ form.handleBlur }
handleChange={ form.handleChange(props.name) }
ref={ ref }
/>
) }
</Field>
);
DropdownSelectFieldProps
> = (props, ref) => {
return (
<Field name={ props.name }>
{ ({ field, form, meta }: FieldProps) => (
<DropdownSelect
{ ...field }
{ ...props }
errorMessage={ meta.touched ? meta.error : "" }
ref={ ref }
onChange={ (event, newValue) => {
form.handleChange(props.name)(newValue);
} }
/>
scandycuz marked this conversation as resolved.
Show resolved Hide resolved
) }
</Field>
);
};

export default forwardRef(DropdownSelectField);
Loading