This commit is contained in:
shafi54 2026-01-30 02:15:17 +05:30
parent 28c7207016
commit a8e52583d4
8 changed files with 3666 additions and 23 deletions

View file

@ -0,0 +1 @@
ALTER TABLE "mf"."addresses" ADD COLUMN "google_maps_url" varchar(500);

File diff suppressed because it is too large Load diff

View file

@ -484,6 +484,13 @@
"when": 1769709890336,
"tag": "0068_colossal_magma",
"breakpoints": true
},
{
"idx": 69,
"version": "7",
"when": 1769718702463,
"tag": "0069_violet_smiling_tiger",
"breakpoints": true
}
]
}

View file

@ -48,6 +48,7 @@ export const addresses = mf.table('addresses', {
isDefault: boolean('is_default').notNull().default(false),
latitude: real('latitude'),
longitude: real('longitude'),
googleMapsUrl: varchar('google_maps_url', { length: 500 }),
adminLatitude: real('admin_latitude'),
adminLongitude: real('admin_longitude'),
zoneId: integer('zone_id').references(() => addressZones.id),

View file

@ -39,16 +39,16 @@ export const addressRouter = router({
isDefault: z.boolean().optional(),
latitude: z.number().optional(),
longitude: z.number().optional(),
googleMapsLocation: z.string().optional(),
googleMapsUrl: z.string().optional(),
}))
.mutation(async ({ input, ctx }) => {
const userId = ctx.user.userId;
const { name, phone, addressLine1, addressLine2, city, state, pincode, isDefault, googleMapsLocation } = input;
const { name, phone, addressLine1, addressLine2, city, state, pincode, isDefault, googleMapsUrl } = input;
let { latitude, longitude } = input;
if (googleMapsLocation && latitude === undefined && longitude === undefined) {
const coords = await extractCoordsFromRedirectUrl(googleMapsLocation);
if (googleMapsUrl && latitude === undefined && longitude === undefined) {
const coords = await extractCoordsFromRedirectUrl(googleMapsUrl);
if (coords) {
latitude = Number(coords.latitude);
longitude = Number(coords.longitude);
@ -77,6 +77,7 @@ export const addressRouter = router({
isDefault: isDefault || false,
latitude,
longitude,
googleMapsUrl,
}).returning();
return { success: true, data: newAddress };
@ -95,16 +96,16 @@ export const addressRouter = router({
isDefault: z.boolean().optional(),
latitude: z.number().optional(),
longitude: z.number().optional(),
googleMapsLocation: z.string().optional(),
googleMapsUrl: z.string().optional(),
}))
.mutation(async ({ input, ctx }) => {
const userId = ctx.user.userId;
const { id, name, phone, addressLine1, addressLine2, city, state, pincode, isDefault, googleMapsLocation } = input;
const { id, name, phone, addressLine1, addressLine2, city, state, pincode, isDefault, googleMapsUrl } = input;
let { latitude, longitude } = input;
if (googleMapsLocation && latitude === undefined && longitude === undefined) {
const coords = await extractCoordsFromRedirectUrl(googleMapsLocation);
if (googleMapsUrl && latitude === undefined && longitude === undefined) {
const coords = await extractCoordsFromRedirectUrl(googleMapsUrl);
if (coords) {
latitude = Number(coords.latitude);
longitude = Number(coords.longitude);
@ -122,7 +123,7 @@ export const addressRouter = router({
await db.update(addresses).set({ isDefault: false }).where(eq(addresses.userId, userId));
}
const [updatedAddress] = await db.update(addresses).set({
const updateData: any = {
name,
phone,
addressLine1,
@ -131,9 +132,17 @@ export const addressRouter = router({
state,
pincode,
isDefault: isDefault || false,
latitude,
longitude,
}).where(and(eq(addresses.id, id), eq(addresses.userId, userId))).returning();
googleMapsUrl,
};
if (latitude !== undefined) {
updateData.latitude = latitude;
}
if (longitude !== undefined) {
updateData.longitude = longitude;
}
const [updatedAddress] = await db.update(addresses).set(updateData).where(and(eq(addresses.id, id), eq(addresses.userId, userId))).returning();
return { success: true, data: updatedAddress };
}),

View file

@ -16,6 +16,9 @@ interface Address {
state: string;
pincode: string;
isDefault: boolean;
latitude?: number | null;
longitude?: number | null;
googleMapsUrl?: string | null;
}
function AddressCard({ address, onEdit, onDelete, onSetDefault, isDeleting }: {
@ -265,6 +268,9 @@ export default function Addresses() {
state: editingAddress.state,
pincode: editingAddress.pincode,
isDefault: editingAddress.isDefault,
latitude: editingAddress.googleMapsUrl ? undefined : (editingAddress.latitude ?? undefined),
longitude: editingAddress.googleMapsUrl ? undefined : (editingAddress.longitude ?? undefined),
googleMapsUrl: editingAddress.googleMapsUrl ?? undefined,
} : undefined}
isEdit={!!editingAddress}
/>

View file

@ -21,7 +21,7 @@ interface AddressFormProps {
isDefault: boolean;
latitude?: number;
longitude?: number;
googleMapsLocation?: string;
googleMapsUrl?: string;
};
isEdit?: boolean;
}
@ -30,7 +30,7 @@ const AddressForm: React.FC<AddressFormProps> = ({ onSuccess, initialValues, isE
const [locationLoading, setLocationLoading] = useState(false);
const [locationError, setLocationError] = useState<string | null>(null);
const [isSubmitting, setIsSubmitting] = useState(false);
const [showGoogleMapsField, setShowGoogleMapsField] = useState(false);
const [showGoogleMapsField, setShowGoogleMapsField] = useState(!!initialValues?.googleMapsUrl);
const [currentLocation, setCurrentLocation] = useState<{ latitude: number; longitude: number } | null>(
initialValues?.latitude && initialValues?.longitude
? { latitude: initialValues.latitude, longitude: initialValues.longitude }
@ -77,6 +77,7 @@ const AddressForm: React.FC<AddressFormProps> = ({ onSuccess, initialValues, isE
const { latitude, longitude } = location.coords;
setCurrentLocation({ latitude, longitude });
Alert.alert('Success', 'Location attached successfully');
} catch (error) {
console.error('Location error:', error);
setLocationError('Unable to fetch location. Please check your GPS settings.');
@ -111,7 +112,7 @@ const AddressForm: React.FC<AddressFormProps> = ({ onSuccess, initialValues, isE
isDefault: false,
latitude: undefined,
longitude: undefined,
googleMapsLocation: '',
googleMapsUrl: '',
}}
validationSchema={validationSchema}
onSubmit={(values) => {
@ -120,7 +121,7 @@ const AddressForm: React.FC<AddressFormProps> = ({ onSuccess, initialValues, isE
...values,
latitude: currentLocation?.latitude,
longitude: currentLocation?.longitude,
googleMapsLocation: values.googleMapsLocation || undefined,
googleMapsUrl: values.googleMapsUrl || undefined,
};
if (isEdit && initialValues?.id) {
updateAddressMutation.mutate({ id: initialValues.id, ...payload });
@ -204,13 +205,13 @@ const AddressForm: React.FC<AddressFormProps> = ({ onSuccess, initialValues, isE
<MyText style={tw`text-red-500 text-sm mb-2`}>{locationError}</MyText>
) : currentLocation ? (
<View style={tw`flex-row items-center mb-4`}>
<MyText style={tw`text-green-600 text-sm font-medium`}>Current Location Attached</MyText>
<MyText style={tw`text-green-600 text-sm font-medium`}>Location Attached</MyText>
<MyTouchableOpacity
onPress={() => attachCurrentLocation()}
disabled={locationLoading}
style={tw`ml-4`}
>
<MyText style={tw`text-blue-500 text-sm font-medium`}>Change</MyText>
<MyText style={tw`text-blue-500 text-sm font-medium`}>Attach Current</MyText>
</MyTouchableOpacity>
</View>
) : (
@ -246,9 +247,9 @@ const AddressForm: React.FC<AddressFormProps> = ({ onSuccess, initialValues, isE
<MyTextInput
placeholder="Google Maps Shared URL"
shrunkPadding={true}
onChangeText={handleChange('googleMapsLocation')}
onBlur={handleBlur('googleMapsLocation')}
value={values.googleMapsLocation}
onChangeText={handleChange('googleMapsUrl')}
onBlur={handleBlur('googleMapsUrl')}
value={values.googleMapsUrl}
/>
</View>
)}

View file

@ -63,8 +63,8 @@ const isDevMode = Constants.executionEnvironment !== "standalone";
// const BASE_API_URL = API_URL;
// const BASE_API_URL = 'http://10.0.2.2:4000';
// const BASE_API_URL = 'http://192.168.100.101:4000';
const BASE_API_URL = 'http://192.168.1.14:4000';
// let BASE_API_URL = "https://mf.freshyo.in";
// const BASE_API_URL = 'http://192.168.1.14:4000';
let BASE_API_URL = "https://mf.freshyo.in";
// let BASE_API_URL = 'http://192.168.100.103:4000';
// let BASE_API_URL = 'http://192.168.29.219:4000';