fix: lint

This commit is contained in:
Michael Zetterberg
2024-04-18 18:08:04 +02:00
parent 285f8bdcfa
commit a512cd04b5
4 changed files with 17 additions and 34 deletions

View File

@@ -27,7 +27,7 @@ export default function FormContent({ control }: EditFormContentProps) {
useEffect(() => { useEffect(() => {
setIsPending(pending) setIsPending(pending)
}, [pending]) }, [pending, setIsPending])
return ( return (
<> <>

View File

@@ -1,6 +1,6 @@
"use client" "use client"
import { useController, useFormContext } from "react-hook-form" import { useController, useFormContext } from "react-hook-form"
import { useEffect, useRef, useState } from "react" import { useRef } from "react"
import { _ } from "@/lib/translation" import { _ } from "@/lib/translation"
import { countries } from "./countries" import { countries } from "./countries"
@@ -28,7 +28,6 @@ export default function CountrySelect({
registerOptions, registerOptions,
}: CountryProps) { }: CountryProps) {
const divRef = useRef<HTMLDivElement>(null) const divRef = useRef<HTMLDivElement>(null)
const [divElement, setDivElement] = useState(divRef.current)
const { control, setValue } = useFormContext() const { control, setValue } = useFormContext()
const { field } = useController({ const { field } = useController({
control, control,
@@ -40,12 +39,6 @@ export default function CountrySelect({
setValue(name, country) setValue(name, country)
} }
useEffect(() => {
if (divRef.current) {
setDivElement(divRef.current)
}
}, [divRef.current])
return ( return (
<div className={styles.container} ref={divRef}> <div className={styles.container} ref={divRef}>
<ComboBox <ComboBox
@@ -81,7 +74,7 @@ export default function CountrySelect({
* by this component to both access css variables assigned * by this component to both access css variables assigned
* on the container as well as to not overflow it at any time. * on the container as well as to not overflow it at any time.
*/ */
UNSTABLE_portalContainer={divElement ?? undefined} UNSTABLE_portalContainer={divRef.current ?? undefined}
> >
<ListBox> <ListBox>
{countries.map((country, idx) => ( {countries.map((country, idx) => (

View File

@@ -1,5 +1,5 @@
"use client" "use client"
import { useEffect, useRef, useState, type FocusEvent } from "react" import { useRef } from "react"
import { import {
Button, Button,
@@ -27,18 +27,11 @@ export default function Select({
value, value,
}: SelectProps) { }: SelectProps) {
const divRef = useRef<HTMLDivElement>(null) const divRef = useRef<HTMLDivElement>(null)
const [divElement, setDivElement] = useState(divRef.current)
function handleOnSelect(key: Key) { function handleOnSelect(key: Key) {
onSelect(key, name) onSelect(key, name)
} }
useEffect(() => {
if (divRef.current) {
setDivElement(divRef.current)
}
}, [divRef.current])
return ( return (
<div className={styles.date} ref={divRef}> <div className={styles.date} ref={divRef}>
<ReactAriaSelect <ReactAriaSelect
@@ -63,7 +56,7 @@ export default function Select({
* by this component to both access css variables assigned * by this component to both access css variables assigned
* on the container as well as to not overflow it at any time. * on the container as well as to not overflow it at any time.
*/ */
UNSTABLE_portalContainer={divElement ?? undefined} UNSTABLE_portalContainer={divRef.current ?? undefined}
> >
<ListBox className={styles.listBox}> <ListBox className={styles.listBox}>
{items.map((item) => ( {items.map((item) => (

View File

@@ -41,21 +41,18 @@ export default function Phone({
rules: registerOptions, rules: registerOptions,
}) })
const handleCountrySelectForPhone = useCallback( const handleCountrySelectForPhone = useCallback((country: string) => {
(country: string) => { const selectedCountry = getCountry({
const selectedCountry = getCountry({ countries: defaultCountries,
countries: defaultCountries, field: "iso2",
field: "iso2", value: country.toLowerCase(),
value: country.toLowerCase(), })
})
if (selectedCountry) { if (selectedCountry) {
phoneRef.current?.setCountry(selectedCountry.iso2) phoneRef.current?.setCountry(selectedCountry.iso2)
prevSelectedCountry.current = country.toLowerCase() prevSelectedCountry.current = country.toLowerCase()
} }
}, }, [])
[phoneRef.current, prevSelectedCountry.current]
)
useEffect(() => { useEffect(() => {
if (countryValue) { if (countryValue) {
@@ -80,7 +77,7 @@ export default function Phone({
handleCountrySelectForPhone(countryValue) handleCountrySelectForPhone(countryValue)
} }
} }
}, [countryValue, prevSelectedCountry.current]) }, [countryValue, field.value, handleCountrySelectForPhone])
return ( return (
<div className={styles.phone}> <div className={styles.phone}>