Skip to content

Instantly share code, notes, and snippets.

@hieptl
Last active December 17, 2021 12:37
Show Gist options
  • Select an option

  • Save hieptl/a6853bc25df06f00a60026d4509cae29 to your computer and use it in GitHub Desktop.

Select an option

Save hieptl/a6853bc25df06f00a60026d4509cae29 to your computer and use it in GitHub Desktop.
doctordetail.js - zocdoc clone
const createCometChatFriend = async () => {
if (!user || !item) {
return;
}
setIsLoading(true);
const cometChatAppId = `${cometChatConfig.cometChatAppId}`;
const cometChatAppRegion = `${cometChatConfig.cometChatRegion}`;
const cometChatApiKey = `${cometChatConfig.cometChatRestApiKey}`;
const url = `https://${cometChatAppId}.api-${cometChatAppRegion}.cometchat.io/v3/users/${user.id}/friends`;
const options = {
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
appId: cometChatAppId,
apiKey: cometChatApiKey,
},
body: JSON.stringify({ accepted: [item.id] }),
};
try {
const response = await fetch(url, options);
if (response) {
alert(`The appointment was created succesfully`);
} else {
alert(`Failure to add create the appointment`);
}
setIsLoading(false);
setHasCreatedAppointment(() => true);
} catch (error) {
console.log(error);
setIsLoading(false);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment