Fix forwardRef and refactor rendering

This commit is contained in:
Justin Edmund 2022-11-30 06:09:55 -08:00
parent 055c70624a
commit 1202985f80

View file

@ -3,23 +3,25 @@ import { useRouter } from "next/router"
import { useTranslation } from "next-i18next" import { useTranslation } from "next-i18next"
import classNames from "classnames" import classNames from "classnames"
import PlusIcon from "~public/icons/Add.svg" import PlusIcon from "~public/icons/Add.svg"
import "./index.scss" import "./index.scss"
// Props // Props
interface Props { interface Props extends React.ComponentPropsWithoutRef<"div"> {
skill?: JobSkill skill?: JobSkill
editable: boolean editable: boolean
hasJob: boolean hasJob: boolean
} }
const JobSkillItem = React.forwardRef<HTMLDivElement, Props>((props, ref) => { const JobSkillItem = React.forwardRef<HTMLDivElement, Props>(
({ ...props }, forwardedRef) => {
const router = useRouter() const router = useRouter()
const { t } = useTranslation("common") const { t } = useTranslation("common")
const locale = const locale =
router.locale && ["en", "ja"].includes(router.locale) ? router.locale : "en" router.locale && ["en", "ja"].includes(router.locale)
? router.locale
: "en"
const classes = classNames({ const classes = classNames({
JobSkill: true, JobSkill: true,
@ -59,24 +61,21 @@ const JobSkillItem = React.forwardRef<HTMLDivElement, Props>((props, ref) => {
if (props.skill) { if (props.skill) {
jsx = <p>{props.skill.name[locale]}</p> jsx = <p>{props.skill.name[locale]}</p>
} else if (props.editable && props.hasJob) { } else if (props.editable && props.hasJob) {
jsx = <p className="placeholder">Select a skill</p> jsx = <p className="placeholder">{t("job_skills.state.selectable")}</p>
} else { } else {
jsx = <p className="placeholder">No skill</p> jsx = <p className="placeholder">{t("job_skills.state.no_skill")}</p>
} }
return jsx return jsx
} }
const skillItem = () => {
return ( return (
<div className={classes} ref={ref}> <div className={classes} onClick={props.onClick} ref={forwardedRef}>
{skillImage()} {skillImage()}
{label()} {label()}
</div> </div>
) )
} }
)
return skillItem()
})
export default JobSkillItem export default JobSkillItem