You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LocationField.js 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import React from "react";
  2. import PropTypes from "prop-types";
  3. import AutoSuggestTextField from "../../../../TextFields/AutoSuggestTextField/AutoSuggestTextField";
  4. import { InputFieldLabelLocation } from "./LocationField.styled";
  5. import { useDispatch, useSelector } from "react-redux";
  6. import { selectLocations } from "../../../../../store/selectors/locationsSelectors";
  7. import { useEffect } from "react";
  8. import { fetchLocations } from "../../../../../store/actions/locations/locationsActions";
  9. import { useTranslation } from "react-i18next";
  10. const LocationField = (props) => {
  11. const { t } = useTranslation();
  12. const locations = useSelector(selectLocations);
  13. const dispatch = useDispatch();
  14. useEffect(() => {
  15. if (locations?.length === 0) {
  16. dispatch(fetchLocations());
  17. }
  18. }, [locations]);
  19. return (
  20. <>
  21. <InputFieldLabelLocation
  22. leftText={t("common.labelLocation").toUpperCase()}
  23. />
  24. <AutoSuggestTextField
  25. editLocation
  26. data={locations.map((item) => ({ name: item.city }))}
  27. value={props.formik.values.firmLocation}
  28. onChange={(event, { newValue }) =>
  29. props.formik.setFieldValue("firmLocation", newValue)
  30. }
  31. />
  32. </>
  33. );
  34. };
  35. LocationField.propTypes = {
  36. formik: PropTypes.any,
  37. };
  38. export default LocationField;