fix(sw-350): Fix issue where value where not updated

This commit is contained in:
Pontus Dreij
2024-11-04 15:49:13 +01:00
parent b69eda9b05
commit cac1a6891e
3 changed files with 13 additions and 12 deletions

View File

@@ -48,13 +48,10 @@ export default function Search({ locations }: SearchProps) {
dispatch({ type: ActionType.CLEAR_HISTORY_LOCATIONS })
}
function handleOnChange(
evt: FormEvent<HTMLInputElement> | ChangeEvent<HTMLInputElement>
) {
const value = evt.currentTarget.value
if (value) {
function dispatchInputValue(inputValue: string) {
if (inputValue) {
dispatch({
payload: { search: value },
payload: { search: inputValue },
type: ActionType.SEARCH_LOCATIONS,
})
} else {
@@ -62,6 +59,14 @@ export default function Search({ locations }: SearchProps) {
}
}
function handleOnChange(
evt: FormEvent<HTMLInputElement> | ChangeEvent<HTMLInputElement>
) {
const newValue = evt.currentTarget.value
setValue(name, newValue)
dispatchInputValue(value)
}
function handleOnFocus(evt: FocusEvent<HTMLInputElement>) {
const searchValue = evt.currentTarget.value
if (searchValue) {
@@ -114,6 +119,7 @@ export default function Search({ locations }: SearchProps) {
inputValue={value}
itemToString={(value) => (value ? value.name : "")}
onSelect={handleOnSelect}
onInputValueChange={(inputValue) => dispatchInputValue(inputValue)}
>
{({
closeMenu,

View File

@@ -65,11 +65,7 @@ export default function Form({ locations, type }: BookingWidgetFormProps) {
id={formId}
>
<input {...register("location")} type="hidden" />
<FormContent
locations={locations}
formId={formId}
formState={formState}
/>
<FormContent locations={locations} formId={formId} />
</form>
</section>
)

View File

@@ -14,7 +14,6 @@ export interface BookingWidgetFormProps {
export interface BookingWidgetFormContentProps {
locations: Locations
formId: string
formState: FormState<BookingWidgetSchema>
}
export enum ActionType {