Browse Source

edit btn fix

Viktoriia 4 weeks ago
parent
commit
622be98d1d

+ 13 - 5
src/components/RegionPopup/index.tsx

@@ -221,7 +221,8 @@ const RegionPopup: React.FC<RegionPopupProps> = ({
             {userData?.visited &&
             userData?.type !== 'dare' &&
             !disabled &&
-            (userData?.visited_regions <= 1 || userData?.type === 'nm') ? (
+            (userData?.visited_regions <= 1 ||
+              (userData?.type === 'nm' && userData?.no_of_visits === 1)) ? (
               <TouchableOpacity
                 onPress={
                   userData?.type === 'countries'
@@ -274,6 +275,9 @@ const RegionPopup: React.FC<RegionPopupProps> = ({
                     ] as never)
                   );
                   return;
+                } else if (userData?.type === 'nm' && userData?.no_of_visits > 1) {
+                  openEditModal();
+                  return;
                 }
 
                 userData?.type === 'nm'
@@ -295,10 +299,14 @@ const RegionPopup: React.FC<RegionPopupProps> = ({
                     : updateDare(region.id, userData.visited ? 0 : 1);
               }}
             >
-              {userData?.visited &&
-              !disabled &&
-              userData?.type === 'countries' &&
-              userData?.visited_regions > 1 ? (
+              {(userData?.visited &&
+                !disabled &&
+                userData?.type === 'countries' &&
+                userData?.visited_regions > 1) ||
+              (userData?.visited &&
+                !disabled &&
+                userData?.type === 'nm' &&
+                userData?.no_of_visits > 1) ? (
                 <View style={styles.visitedContainer}>
                   <EditSvg width={14} height={14} />
                   <Text style={styles.visitedButtonText}>Edit</Text>

+ 20 - 3
src/screens/InAppScreens/MapScreen/RegionViewScreen/index.tsx

@@ -425,7 +425,10 @@ const RegionViewScreen: FC<Props> = ({ navigation, route }) => {
           <View style={styles.nameContainer}>
             <Text style={styles.title}>{name[0]}</Text>
             <View style={ButtonStyles.btnContainer}>
-              {regionData?.visited && type === 'nm' && !disabled ? (
+              {regionData?.visited &&
+              type === 'nm' &&
+              !disabled &&
+              regionData?.no_of_visits === 1 ? (
                 <TouchableOpacity onPress={handleOpenEditModal} style={ButtonStyles.editBtn}>
                   <EditSvg width={14} height={14} />
                 </TouchableOpacity>
@@ -438,9 +441,23 @@ const RegionViewScreen: FC<Props> = ({ navigation, route }) => {
                       ? ButtonStyles.visitedButton
                       : ButtonStyles.markVisitedButton
                   ]}
-                  onPress={() => (type === 'nm' ? handleUpdateNm() : handleUpdateDare())}
+                  onPress={() => {
+                    if (regionData?.type === 'nm' && regionData?.no_of_visits > 1) {
+                      handleOpenEditModal();
+                      return;
+                    }
+                    type === 'nm' ? handleUpdateNm() : handleUpdateDare();
+                  }}
                 >
-                  {regionData?.visited ? (
+                  {regionData?.visited &&
+                  !disabled &&
+                  regionData?.type === 'nm' &&
+                  regionData?.no_of_visits > 1 ? (
+                    <View style={ButtonStyles.visitedContainer}>
+                      <EditSvg width={14} height={14} />
+                      <Text style={ButtonStyles.visitedButtonText}>Edit</Text>
+                    </View>
+                  ) : regionData?.visited ? (
                     <View style={ButtonStyles.visitedContainer}>
                       <MarkIcon width={16} height={16} />
                       <Text style={ButtonStyles.visitedButtonText}>Visited</Text>

+ 0 - 20
src/screens/InAppScreens/TravelsScreen/AddNewTripScreen/index.tsx

@@ -546,16 +546,6 @@ const AddNewTripScreen = ({ route }: { route: any }) => {
               onValueChange={(value: string) => {
                 const month = months?.find((m) => m.label === value);
                 setSelectedMonth(month?.value || null);
-
-                if (selectedDay && month?.value) {
-                  const maxDaysInMonth = moment(
-                    `${selectedYear}-${month.value}`,
-                    'YYYY-M'
-                  ).daysInMonth();
-                  if (selectedDay > maxDaysInMonth) {
-                    setSelectedDay(maxDaysInMonth);
-                  }
-                }
               }}
             />
           </View>
@@ -571,16 +561,6 @@ const AddNewTripScreen = ({ route }: { route: any }) => {
               selectedValue={selectedYear}
               onValueChange={(value: number) => {
                 setSelectedYear(value);
-
-                if (selectedMonth) {
-                  const maxDaysInMonth = moment(
-                    `${value}-${selectedMonth}`,
-                    'YYYY-M'
-                  ).daysInMonth();
-                  if (selectedDay && selectedDay > maxDaysInMonth) {
-                    setSelectedDay(maxDaysInMonth);
-                  }
-                }
               }}
             />
           </View>

+ 14 - 5
src/screens/InAppScreens/TravelsScreen/Components/MyRegionsItems/NmRegionItem.tsx

@@ -102,7 +102,7 @@ export const NmRegionItem = React.memo(
 
           {token && (
             <View style={styles.btnContainer}>
-              {item.visits > 0 ? (
+              {item.visits === 1 ? (
                 <TouchableOpacity onPress={() => openEditModal(item)} style={styles.editBtn}>
                   <EditSvg width={14} height={14} />
                 </TouchableOpacity>
@@ -112,17 +112,26 @@ export const NmRegionItem = React.memo(
                   styles.btn,
                   item.visits > 0 ? styles.visitedButton : styles.markVisitedButton
                 ]}
-                onPress={() =>
+                onPress={() => {
+                  if (item.visits > 1) {
+                    openEditModal(item);
+                    return;
+                  }
                   updateNM(
                     item.id,
                     item.visits > 0 ? 0 : 1,
                     item.visits > 0 ? 0 : 1,
                     item.visits > 0 ? 0 : 1,
                     3
-                  )
-                }
+                  );
+                }}
               >
-                {item.visits > 0 ? (
+                {item.visits > 1 ? (
+                  <View style={styles.visitedContainer}>
+                    <EditSvg width={14} height={14} />
+                    <Text style={styles.visitedButtonText}>Edit</Text>
+                  </View>
+                ) : item.visits > 0 ? (
                   <View style={styles.visitedContainer}>
                     <MarkIcon width={16} height={16} />
                     <Text style={styles.visitedButtonText}>Visited</Text>