Viktoriia 1 year ago
parent
commit
c4c4aeda19

+ 2 - 0
src/components/WarningModal/index.tsx

@@ -51,6 +51,7 @@ export const WarningModal = ({
           textColor: Colors.DARK_BLUE,
           color: Colors.WHITE,
           action: () => {
+            action && action();
             onClose();
             navigation.navigate(NAVIGATION_PAGES.LOGIN as never);
           },
@@ -61,6 +62,7 @@ export const WarningModal = ({
           textColor: Colors.WHITE,
           color: Colors.DARK_BLUE,
           action: () => {
+            action && action();
             onClose();
             navigation.navigate(NAVIGATION_PAGES.REGISTER as never);
           },

+ 20 - 6
src/screens/InAppScreens/MapScreen/UniversalSearch/index.tsx

@@ -9,7 +9,8 @@ import { Colors } from 'src/theme';
 import { styles } from './styles';
 import { NAVIGATION_PAGES } from 'src/types';
 import { API_HOST } from 'src/constants';
-import { Loading } from 'src/components';
+import { Loading, WarningModal } from 'src/components';
+import { StoreType, storage } from 'src/storage';
 
 const SearchModal = ({
   searchVisible,
@@ -17,7 +18,8 @@ const SearchModal = ({
   handleFindRegion,
   index,
   searchData,
-  setIndex
+  setIndex,
+  token
 }: {
   searchVisible: boolean;
   handleCloseModal: () => void;
@@ -25,6 +27,7 @@ const SearchModal = ({
   index: number;
   searchData: any;
   setIndex: (index: number) => void;
+  token: string | undefined;
 }) => {
   const navigation = useNavigation();
   const [routes] = useState([
@@ -33,6 +36,7 @@ const SearchModal = ({
     { key: 'dare', title: 'Places' }
   ]);
   const [shouldOpenModal, setShouldOpenModal] = useState<{ id: number; type: string } | null>(null);
+  const [warningVisible, setWarningVisible] = useState(false);
 
   const renderItem = ({ item }: { item: any }) => {
     const name = item.name?.split(/ – | - /);
@@ -41,10 +45,14 @@ const SearchModal = ({
       <TouchableOpacity
         style={{ paddingVertical: 12 }}
         onPress={() => {
-          handleCloseModal();
-          navigation.navigate(
-            ...([NAVIGATION_PAGES.PUBLIC_PROFILE_VIEW, { userId: item.id }] as never)
-          );
+          if (!token) {
+            setWarningVisible(true);
+          } else {
+            handleCloseModal();
+            navigation.navigate(
+              ...([NAVIGATION_PAGES.PUBLIC_PROFILE_VIEW, { userId: item.id }] as never)
+            );
+          }
         }}
       >
         <View style={styles.container}>
@@ -122,6 +130,12 @@ const SearchModal = ({
         ) : (
           <Loading />
         )}
+        <WarningModal
+          type="unauthorized"
+          isVisible={warningVisible}
+          onClose={() => setWarningVisible(false)}
+          action={handleCloseModal}
+        />
       </View>
     );
   };

+ 1 - 0
src/screens/InAppScreens/MapScreen/index.tsx

@@ -835,6 +835,7 @@ const MapScreen: React.FC<MapScreenProps> = ({ navigation }) => {
         index={index}
         searchData={searchData}
         setIndex={setIndex}
+        token={token}
       />
     </View>
   );