Skip to content
This repository was archived by the owner on Feb 2, 2024. It is now read-only.

feat: business removal from map #122

Merged
merged 2 commits into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ check-code:

test:
yarn test

codegen:
yarn dev:codegen
25 changes: 24 additions & 1 deletion components/account/business-map-update.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@ const isValidBusinessInfo = ({ title, coordinates }: AccountBusinessInfo) =>
const BusinessMapUpdate: React.FC<{
accountDetails: AccountData
update: (info: AccountBusinessInfo) => void
deleteBusiness: (username: string) => void
updating: boolean
loading: boolean
}> = ({ accountDetails, update, updating = false, loading = false }) => {
}> = ({ accountDetails, update, deleteBusiness, updating = false, loading = false }) => {
const data = accountDetails

const [title, setTitle] = useState(data?.title || "")
const [latitude, setLatitude] = useState<number | "">(data?.coordinates?.latitude || "")
const [longitude, setLongitude] = useState<number | "">(
data?.coordinates?.longitude || "",
)
const [username] = useState<string>(data?.username || "")

const emptyClass = loading ? "filter blur-sm animate-pulse" : ""

Expand Down Expand Up @@ -54,6 +56,17 @@ const BusinessMapUpdate: React.FC<{
alert("Invalid business info")
}

const submitDelete: React.FormEventHandler<HTMLFormElement> = async (event) => {
event.preventDefault()

if (deleteBusiness) {
deleteBusiness(username)
return
}

alert("Invalid username")
}

return (
<div className="shadow p-6 min-w-0 rounded-lg shadow-xs overflow-hidden bg-white grid grid-cols-1 gap-4">
<form className="grid grid-cols-2 gap-4" onSubmit={submit}>
Expand Down Expand Up @@ -122,6 +135,16 @@ const BusinessMapUpdate: React.FC<{
</button>
</div>
</form>
<form className="grid grid-cols-2 gap-4" onSubmit={submitDelete}>
<div className={`${emptyClass} flex items-end justify-end`}>
<button
type="submit"
className="mb-0 w-full bg-blue-400 hover:bg-red-500 text-white font-bold p-2 my-4 border border-blue-500 rounded disabled:opacity-50"
>
{"Delete"}
</button>
</div>
</form>
</div>
)
}
Expand Down
27 changes: 27 additions & 0 deletions components/account/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
ACCOUNTS_ADD_USD_WALLET,
ACCOUNT_UPDATE_LEVEL,
BUSINESS_UPDATE_MAP_INFO,
BUSINESS_DELETE_MAP,
} from "../../graphql/mutations"
import { AccountLevel, AccountStatus, WalletCurrency } from "../../graphql/types"

Expand Down Expand Up @@ -153,6 +154,23 @@ function AccountDetails() {
},
)

const [deleteBusiness] = useMutation(
BUSINESS_DELETE_MAP,
{
onCompleted({ businessDeleteMapInfo }) {
if (businessDeleteMapInfo.accountDetails) {
updateData(businessDeleteMapInfo.accountDetails)
const usernameOrPhone =
businessDeleteMapInfo.accountDetails.username ??
businessDeleteMapInfo.accountDetails.owner.phone
alert(`${usernameOrPhone}'s business has been deleted successfully from map`)
}
},
onError: reportError,
fetchPolicy: "no-cache",
},
)

const loading = loadingAccountByPhone || loadingAccountByUsername

const usernameOrPhone = data?.username ?? data?.owner.phone
Expand Down Expand Up @@ -218,6 +236,14 @@ function AccountDetails() {
alert("Username is required")
}

const deleteBusinessDetails = (username: string) => {
if (!username) {
return
}
const input = { username }
return deleteBusiness({ variables: { input } })
}

return (
<>
<SearchHeader
Expand Down Expand Up @@ -254,6 +280,7 @@ function AccountDetails() {
<BusinessMapUpdate
accountDetails={data}
update={changeBusinessMapDetails}
deleteBusiness={deleteBusinessDetails}
updating={loadingBusinessMap}
loading={loading}
/>
Expand Down
6 changes: 3 additions & 3 deletions graphql/__generated__/fragment-masking.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 20 additions & 15 deletions graphql/__generated__/gql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading