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

View File

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

View File

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