Skip to content

Commit

Permalink
chore: misc changes
Browse files Browse the repository at this point in the history
  • Loading branch information
siddhart1o1 committed Feb 8, 2024
1 parent d8595fd commit cfff024
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 26 deletions.
12 changes: 9 additions & 3 deletions apps/map/app/server-acton.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use server"

import { merchantMapSuggest } from "@/services/galoy/graphql/mutation/merchant-map-suggest"
import { isValidCoordinates } from "./utils"

export const submitMerchantSuggest = async (
_prevState: {
Expand Down Expand Up @@ -32,10 +33,15 @@ export const submitMerchantSuggest = async (
}
}

const lat = parseFloat(latitude)
const lon = parseFloat(longitude)
const lat = Number(latitude)
const lon = Number(longitude)

if (isNaN(lat) || isNaN(lon) || lat < -90 || lat > 90 || lon < -180 || lon > 180) {
if (
isValidCoordinates({
latitude: lat,
longitude: lon,
})
) {
return {
error: true,
message: "Invalid coordinates",
Expand Down
11 changes: 11 additions & 0 deletions apps/map/app/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export function isValidCoordinates({
latitude,
longitude,
}: {
latitude: number
longitude: number
}): boolean {
const isValidLatitude: boolean = latitude >= -90 && latitude <= 90
const isValidLongitude: boolean = longitude >= -180 && longitude <= 180
return isValidLatitude && isValidLongitude
}
28 changes: 10 additions & 18 deletions apps/map/components/map/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,28 +198,20 @@ export default function MapComponent({ mapData }: MapComponentProps) {
)}

{draggablePin.visible && (
<div className="absolute bottom-4 left-1/2 transform -translate-x-1/2 z-10 bg-white text-black p-2 rounded-md flex justify-center gap-8">
<button style={{ display: draggablePin.visible ? "block" : "none" }}>
<SuggestMapFormSheet
latitude={draggablePin.coordinates.lat}
longitude={draggablePin.coordinates.lng}
/>
</button>
<button
onClick={cancelDraggablePin}
style={{ display: draggablePin.visible ? "block" : "none" }}
>
Cancel
</button>
<div className="absolute bottom-4 left-1/2 transform -translate-x-1/2 z-10 bg-white text-black p-1 rounded-full flex justify-center text-sm gap-4 pr-3 pl-1">
<SuggestMapFormSheet
latitude={draggablePin.coordinates.lat}
longitude={draggablePin.coordinates.lng}
/>
<button onClick={cancelDraggablePin}>Cancel</button>
</div>
)}
{!draggablePin.visible && (
<button
className="absolute bottom-4 left-1/2 transform -translate-x-1/2 z-10 bg-white text-black p-2 rounded-md"
className="absolute bottom-4 left-1/2 transform -translate-x-1/2 z-10 bg-white text-black p-2 pr-3 pl-3 rounded-full text-sm"
onClick={addDraggablePin}
style={{ display: draggablePin.visible ? "none" : "block" }}
>
Add Business Location
Add New Location
</button>
)}
{currentLocation.userAllowedLocation && (
Expand All @@ -239,7 +231,7 @@ export default function MapComponent({ mapData }: MapComponentProps) {
mapTypeId={google.maps.MapTypeId.ROADMAP}
mapContainerStyle={{ width: "100vw", height: "100vh" }}
>
{mapData.map((marker) => (
{mapData.map((marker, index) => (
<MarkerF
icon={{
path: "M 0,0 C -2,-20 -10,-22 -10,-30 A 10,10 0 1,1 10,-30 C 10,-22 2,-20 0,0 z",
Expand All @@ -249,7 +241,7 @@ export default function MapComponent({ mapData }: MapComponentProps) {
strokeColor: "gold",
scale: 0.8,
}}
key={marker.username}
key={index}
position={{
lat: marker.mapInfo.coordinates.latitude,
lng: marker.mapInfo.coordinates.longitude,
Expand Down
14 changes: 9 additions & 5 deletions apps/map/components/map/suggest-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,17 @@ export function SuggestMapFormSheet({ latitude, longitude }: formProps) {
const handleOpen = () => {
state.error = false
state.message = ""
setCoordinates({
latitude,
longitude,
})
setIsOpen(true)
}

return (
<Sheet open={isOpen} onOpenChange={setIsOpen}>
<SheetTrigger asChild>
<button className="bg-orange-500 p-1 text-white rounded-md" onClick={handleOpen}>
<button className="bg-orange-500 p-1 pr-2 pl-2 text-white rounded-full" onClick={handleOpen}>
Confirm
</button>
</SheetTrigger>
Expand Down Expand Up @@ -82,7 +86,7 @@ export function SuggestMapFormSheet({ latitude, longitude }: formProps) {
name="latitude"
type="number"
onChange={(e) => {
setCoordinates({ ...coordinates, latitude: parseFloat(e.target.value) })
setCoordinates({ ...coordinates, latitude: Number(e.target.value) })
}}
/>
<InputComponent
Expand All @@ -96,16 +100,16 @@ export function SuggestMapFormSheet({ latitude, longitude }: formProps) {
onChange={(e) => {
setCoordinates({
...coordinates,
longitude: parseFloat(e.target.value),
longitude: Number(e.target.value),
})
}}
/>
{state.error && <span className="text-red-600">{state.message}</span>}
<button
className="mt-2 bg-orange-500 p-2 text-white rounded-lg"
className="mt-2 bg-orange-500 p-2 text-white rounded-full"
type="submit"
>
Suggest
Submit Request
</button>
</form>
</>
Expand Down

0 comments on commit cfff024

Please sign in to comment.