diff --git a/src/Components/Profile/Subcomponents/ProfileTextForm.tsx b/src/Components/Profile/Subcomponents/ProfileTextForm.tsx
index e8ba5352..6df91ef6 100644
--- a/src/Components/Profile/Subcomponents/ProfileTextForm.tsx
+++ b/src/Components/Profile/Subcomponents/ProfileTextForm.tsx
@@ -38,7 +38,7 @@ export const ProfileTextForm = ({
return (
diff --git a/src/Components/Profile/Subcomponents/TagsWidget.tsx b/src/Components/Profile/Subcomponents/TagsWidget.tsx
index 0faa26bc..193a6cbb 100644
--- a/src/Components/Profile/Subcomponents/TagsWidget.tsx
+++ b/src/Components/Profile/Subcomponents/TagsWidget.tsx
@@ -33,6 +33,9 @@ export const TagsWidget = ({ placeholder, containerStyle, defaultTags, onUpdate
}
const onKeyDown = (e) => {
+ if (e.key === 'Enter') {
+ e.preventDefault()
+ }
const { key } = e
const trimmedInput = input.trim()
@@ -42,7 +45,6 @@ export const TagsWidget = ({ placeholder, containerStyle, defaultTags, onUpdate
// eslint-disable-next-line react/prop-types
!defaultTags.some((tag) => tag.name.toLocaleLowerCase() === trimmedInput.toLocaleLowerCase())
) {
- e.preventDefault()
const newTag = tags.find((t) => t.name === trimmedInput.toLocaleLowerCase())
newTag && onUpdate([...currentTags, newTag])
!newTag &&
diff --git a/src/Components/Profile/Templates/TabsForm.tsx b/src/Components/Profile/Templates/TabsForm.tsx
index 375caa76..d722fd25 100644
--- a/src/Components/Profile/Templates/TabsForm.tsx
+++ b/src/Components/Profile/Templates/TabsForm.tsx
@@ -6,7 +6,6 @@
/* eslint-disable @typescript-eslint/restrict-plus-operands */
/* eslint-disable @typescript-eslint/no-unsafe-return */
/* eslint-disable react/prop-types */
-import { useCallback, useEffect, useState } from 'react'
import { useNavigate } from 'react-router-dom'
import { RichTextEditor } from '#components/Input/RichTextEditor'
@@ -15,6 +14,7 @@ import { PopupStartEndInput, TextView } from '#components/Map/Subcomponents/Item
import { ActionButton } from '#components/Profile/Subcomponents/ActionsButton'
import { LinkedItemsHeaderView } from '#components/Profile/Subcomponents/LinkedItemsHeaderView'
import { TagsWidget } from '#components/Profile/Subcomponents/TagsWidget'
+import { Tabs } from '#components/Templates/Tabs'
export const TabsForm = ({
item,
@@ -26,114 +26,70 @@ export const TabsForm = ({
loading,
setUrlParams,
}) => {
- const [activeTab, setActiveTab] = useState
(1)
- const navigate = useNavigate()
const updateItem = useUpdateItem()
-
- const updateActiveTab = useCallback(
- (id: number) => {
- setActiveTab(id)
-
- const params = new URLSearchParams(window.location.search)
-
- params.set('tab', `${id}`)
- const newUrl = location.pathname + '?' + params.toString()
- window.history.pushState({}, '', newUrl)
- setUrlParams(params)
- },
- // eslint-disable-next-line react-hooks/exhaustive-deps
- [location.pathname],
- )
-
- useEffect(() => {
- const params = new URLSearchParams(location.search)
- const urlTab = params.get('tab')
- setActiveTab(urlTab ? Number(urlTab) : 1)
- // eslint-disable-next-line react-hooks/exhaustive-deps
- }, [location.search])
+ const navigate = useNavigate()
return (
-
-
-
updateActiveTab(1)}
- />
-
-
- {item.layer.itemType.show_start_end_input && (
-
- setState((prevState) => ({
- ...prevState,
- end: e,
- }))
- }
- updateStartValue={(s) =>
- setState((prevState) => ({
- ...prevState,
- start: s,
- }))
- }
- >
- )}
+
+
+ {item.layer.itemType.show_start_end_input && (
+
+ setState((prevState) => ({
+ ...prevState,
+ end: e,
+ }))
+ }
+ updateStartValue={(s) =>
+ setState((prevState) => ({
+ ...prevState,
+ start: s,
+ }))
+ }
+ >
+ )}
-
- setState((prevState) => ({
- ...prevState,
- text: v,
- }))
- }
- containerStyle='tw:pt-2 tw:grow'
- inputStyle={`tw:h-full ${!item.layer.itemType.show_start_end_input && 'tw:border-t-0 tw:rounded-tl-none'}`}
- />
-
- setState((prevState) => ({
- ...prevState,
- contact: c,
- }))
- }
- inputStyle=''
- containerStyle='tw:pt-2 tw:h-36 tw:flex-none'
- required={false}
- />
-
-
- {item.layer?.itemType.offers_and_needs && (
- <>
-
updateActiveTab(3)}
- />
-
+
+ setState((prevState) => ({
+ ...prevState,
+ text: v,
+ }))
+ }
+ containerStyle='tw:pt-2 tw:flex-1 tw:min-h-36 tw:max-h-136'
+ />
+
+ setState((prevState) => ({
+ ...prevState,
+ contact: c,
+ }))
+ }
+ containerStyle='tw:pt-2 tw:h-36 tw:flex-none'
+ required={false}
+ />
+
+ ),
+ },
+ {
+ title: 'Offers & Needs',
+ component: (
-
- >
- )}
- {item.layer?.itemType.relations && (
- <>
-
updateActiveTab(7)}
- />
-
+ ),
+ },
+ {
+ title: 'Links',
+ component: (
{state.relations &&
@@ -211,10 +154,10 @@ export const TabsForm = ({
)}
-
- >
- )}
-
+ ),
+ },
+ ]}
+ >
)
}
diff --git a/src/Components/Profile/Templates/TabsView.tsx b/src/Components/Profile/Templates/TabsView.tsx
index 5dce43a4..626a0b8f 100644
--- a/src/Components/Profile/Templates/TabsView.tsx
+++ b/src/Components/Profile/Templates/TabsView.tsx
@@ -91,9 +91,9 @@ export const TabsView = ({
name='my_tabs_2'
role='tab'
className={'tw:tab tw:font-bold tw:ps-2! tw:pe-2! '}
- aria-label={`${item.layer?.itemType.icon_as_labels && activeTab !== 1 ? '📝' : '📝\u00A0Info'}`}
- checked={activeTab === 1 && true}
- onChange={() => updateActiveTab(1)}
+ aria-label={`${item.layer?.itemType.icon_as_labels && activeTab !== 0 ? '📝' : '📝\u00A0Info'}`}
+ checked={activeTab === 0 && true}
+ onChange={() => updateActiveTab(0)}
/>
updateActiveTab(2)}
+ aria-label={`${item.layer.itemType.icon_as_labels && activeTab !== 3 ? '❤️' : '❤️\u00A0Trust'}`}
+ checked={activeTab === 3 && true}
+ onChange={() => updateActiveTab(3)}
/>
updateActiveTab(3)}
+ className={`tw:tab tw:font-bold tw:ps-2! tw:pe-2! ${!(item.layer.itemType.icon_as_labels && activeTab !== 1) && 'tw:min-w-[10.4em]'} `}
+ aria-label={`${item.layer.itemType.icon_as_labels && activeTab !== 1 ? '♻️' : '♻️\u00A0Offers & Needs'}`}
+ checked={activeTab === 1 && true}
+ onChange={() => updateActiveTab(1)}
/>
updateActiveTab(7)}
+ aria-label={`${item.layer.itemType.icon_as_labels && activeTab !== 2 ? '🔗' : '🔗\u00A0Links'}`}
+ checked={activeTab === 2 && true}
+ onChange={() => updateActiveTab(2)}
/>
void
+}
+
+export const Tabs: React.FC
= ({ items, setUrlParams }: TabsProps) => {
+ const location = useLocation()
+ const navigate = useNavigate()
+
+ const [activeIndex, setActiveIndex] = useState(0)
+
+ useEffect(() => {
+ const params = new URLSearchParams(location.search)
+ const urlTab = params.get('tab')
+ if (urlTab !== null && !isNaN(Number(urlTab))) {
+ const index = Number(urlTab)
+ if (index >= 0 && index < items.length) {
+ setActiveIndex(index)
+ }
+ }
+ }, [items.length, location.search])
+
+ const updateActiveTab = useCallback(
+ (index: number) => {
+ setActiveIndex(index)
+
+ const params = new URLSearchParams(location.search)
+ params.set('tab', `${index}`)
+ setUrlParams(params)
+ const newUrl = location.pathname + '?' + params.toString()
+
+ navigate(newUrl, { replace: false })
+ },
+ [location, navigate],
+ )
+
+ return (
+
+
+ {items.map((item, index) => (
+
updateActiveTab(index)}
+ >
+ {item.title}
+
+ ))}
+
+
+ {items[activeIndex]?.component}
+
+
+ )
+}