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

add error checks to account search #39

Merged
merged 2 commits into from
Jun 17, 2022
Merged
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
12 changes: 7 additions & 5 deletions src/components/AccountDetails/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ function AccountDetails() {
const [data, setData] = useState(null)
const [searchValue, setSearchValue] = useState("")
const onError = (error) => {
reportError(error.message)
setData(null)
reportError(error?.graphQLErrors?.[0]?.code + ": " + error.message)
}

const queryOptions = {
onCompleted({ accountDetails }) {
setData(accountDetails)
onCompleted(data) {
if (data?.accountDetails) {
setData(data?.accountDetails)
}
},
onError,
fetchPolicy: "no-cache",
Expand Down Expand Up @@ -89,10 +90,11 @@ function AccountDetails() {
if (searchValue && validPhone(searchValue)) {
return getAccountByUserPhone({ variables: { phone: searchValue } })
}

if (searchValue && validUsername(searchValue)) {
return getAccountByUsername({ variables: { username: searchValue } })
}
// invalid search
alert("Please enter a full phone number or username")
}

const changeLevel = () => {
Expand Down