enh
This commit is contained in:
parent
28c7207016
commit
a8e52583d4
8 changed files with 3666 additions and 23 deletions
1
apps/backend/drizzle/0069_violet_smiling_tiger.sql
Normal file
1
apps/backend/drizzle/0069_violet_smiling_tiger.sql
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
ALTER TABLE "mf"."addresses" ADD COLUMN "google_maps_url" varchar(500);
|
||||||
3618
apps/backend/drizzle/meta/0069_snapshot.json
Normal file
3618
apps/backend/drizzle/meta/0069_snapshot.json
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -484,6 +484,13 @@
|
||||||
"when": 1769709890336,
|
"when": 1769709890336,
|
||||||
"tag": "0068_colossal_magma",
|
"tag": "0068_colossal_magma",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 69,
|
||||||
|
"version": "7",
|
||||||
|
"when": 1769718702463,
|
||||||
|
"tag": "0069_violet_smiling_tiger",
|
||||||
|
"breakpoints": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
@ -48,6 +48,7 @@ export const addresses = mf.table('addresses', {
|
||||||
isDefault: boolean('is_default').notNull().default(false),
|
isDefault: boolean('is_default').notNull().default(false),
|
||||||
latitude: real('latitude'),
|
latitude: real('latitude'),
|
||||||
longitude: real('longitude'),
|
longitude: real('longitude'),
|
||||||
|
googleMapsUrl: varchar('google_maps_url', { length: 500 }),
|
||||||
adminLatitude: real('admin_latitude'),
|
adminLatitude: real('admin_latitude'),
|
||||||
adminLongitude: real('admin_longitude'),
|
adminLongitude: real('admin_longitude'),
|
||||||
zoneId: integer('zone_id').references(() => addressZones.id),
|
zoneId: integer('zone_id').references(() => addressZones.id),
|
||||||
|
|
|
||||||
|
|
@ -39,16 +39,16 @@ export const addressRouter = router({
|
||||||
isDefault: z.boolean().optional(),
|
isDefault: z.boolean().optional(),
|
||||||
latitude: z.number().optional(),
|
latitude: z.number().optional(),
|
||||||
longitude: z.number().optional(),
|
longitude: z.number().optional(),
|
||||||
googleMapsLocation: z.string().optional(),
|
googleMapsUrl: z.string().optional(),
|
||||||
}))
|
}))
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const userId = ctx.user.userId;
|
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;
|
let { latitude, longitude } = input;
|
||||||
|
|
||||||
if (googleMapsLocation && latitude === undefined && longitude === undefined) {
|
if (googleMapsUrl && latitude === undefined && longitude === undefined) {
|
||||||
const coords = await extractCoordsFromRedirectUrl(googleMapsLocation);
|
const coords = await extractCoordsFromRedirectUrl(googleMapsUrl);
|
||||||
if (coords) {
|
if (coords) {
|
||||||
latitude = Number(coords.latitude);
|
latitude = Number(coords.latitude);
|
||||||
longitude = Number(coords.longitude);
|
longitude = Number(coords.longitude);
|
||||||
|
|
@ -77,6 +77,7 @@ export const addressRouter = router({
|
||||||
isDefault: isDefault || false,
|
isDefault: isDefault || false,
|
||||||
latitude,
|
latitude,
|
||||||
longitude,
|
longitude,
|
||||||
|
googleMapsUrl,
|
||||||
}).returning();
|
}).returning();
|
||||||
|
|
||||||
return { success: true, data: newAddress };
|
return { success: true, data: newAddress };
|
||||||
|
|
@ -95,16 +96,16 @@ export const addressRouter = router({
|
||||||
isDefault: z.boolean().optional(),
|
isDefault: z.boolean().optional(),
|
||||||
latitude: z.number().optional(),
|
latitude: z.number().optional(),
|
||||||
longitude: z.number().optional(),
|
longitude: z.number().optional(),
|
||||||
googleMapsLocation: z.string().optional(),
|
googleMapsUrl: z.string().optional(),
|
||||||
}))
|
}))
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const userId = ctx.user.userId;
|
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;
|
let { latitude, longitude } = input;
|
||||||
|
|
||||||
if (googleMapsLocation && latitude === undefined && longitude === undefined) {
|
if (googleMapsUrl && latitude === undefined && longitude === undefined) {
|
||||||
const coords = await extractCoordsFromRedirectUrl(googleMapsLocation);
|
const coords = await extractCoordsFromRedirectUrl(googleMapsUrl);
|
||||||
if (coords) {
|
if (coords) {
|
||||||
latitude = Number(coords.latitude);
|
latitude = Number(coords.latitude);
|
||||||
longitude = Number(coords.longitude);
|
longitude = Number(coords.longitude);
|
||||||
|
|
@ -122,7 +123,7 @@ export const addressRouter = router({
|
||||||
await db.update(addresses).set({ isDefault: false }).where(eq(addresses.userId, userId));
|
await db.update(addresses).set({ isDefault: false }).where(eq(addresses.userId, userId));
|
||||||
}
|
}
|
||||||
|
|
||||||
const [updatedAddress] = await db.update(addresses).set({
|
const updateData: any = {
|
||||||
name,
|
name,
|
||||||
phone,
|
phone,
|
||||||
addressLine1,
|
addressLine1,
|
||||||
|
|
@ -131,9 +132,17 @@ export const addressRouter = router({
|
||||||
state,
|
state,
|
||||||
pincode,
|
pincode,
|
||||||
isDefault: isDefault || false,
|
isDefault: isDefault || false,
|
||||||
latitude,
|
googleMapsUrl,
|
||||||
longitude,
|
};
|
||||||
}).where(and(eq(addresses.id, id), eq(addresses.userId, userId))).returning();
|
|
||||||
|
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 };
|
return { success: true, data: updatedAddress };
|
||||||
}),
|
}),
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,9 @@ interface Address {
|
||||||
state: string;
|
state: string;
|
||||||
pincode: string;
|
pincode: string;
|
||||||
isDefault: boolean;
|
isDefault: boolean;
|
||||||
|
latitude?: number | null;
|
||||||
|
longitude?: number | null;
|
||||||
|
googleMapsUrl?: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function AddressCard({ address, onEdit, onDelete, onSetDefault, isDeleting }: {
|
function AddressCard({ address, onEdit, onDelete, onSetDefault, isDeleting }: {
|
||||||
|
|
@ -265,6 +268,9 @@ export default function Addresses() {
|
||||||
state: editingAddress.state,
|
state: editingAddress.state,
|
||||||
pincode: editingAddress.pincode,
|
pincode: editingAddress.pincode,
|
||||||
isDefault: editingAddress.isDefault,
|
isDefault: editingAddress.isDefault,
|
||||||
|
latitude: editingAddress.googleMapsUrl ? undefined : (editingAddress.latitude ?? undefined),
|
||||||
|
longitude: editingAddress.googleMapsUrl ? undefined : (editingAddress.longitude ?? undefined),
|
||||||
|
googleMapsUrl: editingAddress.googleMapsUrl ?? undefined,
|
||||||
} : undefined}
|
} : undefined}
|
||||||
isEdit={!!editingAddress}
|
isEdit={!!editingAddress}
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ interface AddressFormProps {
|
||||||
isDefault: boolean;
|
isDefault: boolean;
|
||||||
latitude?: number;
|
latitude?: number;
|
||||||
longitude?: number;
|
longitude?: number;
|
||||||
googleMapsLocation?: string;
|
googleMapsUrl?: string;
|
||||||
};
|
};
|
||||||
isEdit?: boolean;
|
isEdit?: boolean;
|
||||||
}
|
}
|
||||||
|
|
@ -30,7 +30,7 @@ const AddressForm: React.FC<AddressFormProps> = ({ onSuccess, initialValues, isE
|
||||||
const [locationLoading, setLocationLoading] = useState(false);
|
const [locationLoading, setLocationLoading] = useState(false);
|
||||||
const [locationError, setLocationError] = useState<string | null>(null);
|
const [locationError, setLocationError] = useState<string | null>(null);
|
||||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
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>(
|
const [currentLocation, setCurrentLocation] = useState<{ latitude: number; longitude: number } | null>(
|
||||||
initialValues?.latitude && initialValues?.longitude
|
initialValues?.latitude && initialValues?.longitude
|
||||||
? { latitude: initialValues.latitude, longitude: 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;
|
const { latitude, longitude } = location.coords;
|
||||||
setCurrentLocation({ latitude, longitude });
|
setCurrentLocation({ latitude, longitude });
|
||||||
|
Alert.alert('Success', 'Location attached successfully');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Location error:', error);
|
console.error('Location error:', error);
|
||||||
setLocationError('Unable to fetch location. Please check your GPS settings.');
|
setLocationError('Unable to fetch location. Please check your GPS settings.');
|
||||||
|
|
@ -111,7 +112,7 @@ const AddressForm: React.FC<AddressFormProps> = ({ onSuccess, initialValues, isE
|
||||||
isDefault: false,
|
isDefault: false,
|
||||||
latitude: undefined,
|
latitude: undefined,
|
||||||
longitude: undefined,
|
longitude: undefined,
|
||||||
googleMapsLocation: '',
|
googleMapsUrl: '',
|
||||||
}}
|
}}
|
||||||
validationSchema={validationSchema}
|
validationSchema={validationSchema}
|
||||||
onSubmit={(values) => {
|
onSubmit={(values) => {
|
||||||
|
|
@ -120,7 +121,7 @@ const AddressForm: React.FC<AddressFormProps> = ({ onSuccess, initialValues, isE
|
||||||
...values,
|
...values,
|
||||||
latitude: currentLocation?.latitude,
|
latitude: currentLocation?.latitude,
|
||||||
longitude: currentLocation?.longitude,
|
longitude: currentLocation?.longitude,
|
||||||
googleMapsLocation: values.googleMapsLocation || undefined,
|
googleMapsUrl: values.googleMapsUrl || undefined,
|
||||||
};
|
};
|
||||||
if (isEdit && initialValues?.id) {
|
if (isEdit && initialValues?.id) {
|
||||||
updateAddressMutation.mutate({ id: initialValues.id, ...payload });
|
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>
|
<MyText style={tw`text-red-500 text-sm mb-2`}>{locationError}</MyText>
|
||||||
) : currentLocation ? (
|
) : currentLocation ? (
|
||||||
<View style={tw`flex-row items-center mb-4`}>
|
<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
|
<MyTouchableOpacity
|
||||||
onPress={() => attachCurrentLocation()}
|
onPress={() => attachCurrentLocation()}
|
||||||
disabled={locationLoading}
|
disabled={locationLoading}
|
||||||
style={tw`ml-4`}
|
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>
|
</MyTouchableOpacity>
|
||||||
</View>
|
</View>
|
||||||
) : (
|
) : (
|
||||||
|
|
@ -246,9 +247,9 @@ const AddressForm: React.FC<AddressFormProps> = ({ onSuccess, initialValues, isE
|
||||||
<MyTextInput
|
<MyTextInput
|
||||||
placeholder="Google Maps Shared URL"
|
placeholder="Google Maps Shared URL"
|
||||||
shrunkPadding={true}
|
shrunkPadding={true}
|
||||||
onChangeText={handleChange('googleMapsLocation')}
|
onChangeText={handleChange('googleMapsUrl')}
|
||||||
onBlur={handleBlur('googleMapsLocation')}
|
onBlur={handleBlur('googleMapsUrl')}
|
||||||
value={values.googleMapsLocation}
|
value={values.googleMapsUrl}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
)}
|
)}
|
||||||
|
|
|
||||||
|
|
@ -63,8 +63,8 @@ const isDevMode = Constants.executionEnvironment !== "standalone";
|
||||||
// const BASE_API_URL = API_URL;
|
// const BASE_API_URL = API_URL;
|
||||||
// const BASE_API_URL = 'http://10.0.2.2:4000';
|
// 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.100.101:4000';
|
||||||
const BASE_API_URL = 'http://192.168.1.14:4000';
|
// const BASE_API_URL = 'http://192.168.1.14:4000';
|
||||||
// let BASE_API_URL = "https://mf.freshyo.in";
|
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.100.103:4000';
|
||||||
// let BASE_API_URL = 'http://192.168.29.219:4000';
|
// let BASE_API_URL = 'http://192.168.29.219:4000';
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue