-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2357082
commit 421307d
Showing
11 changed files
with
425 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
packages/examples/sdk-frontend-react/src/app/ChatTest/GetGroupMemberStatusTest.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { useState, useContext } from 'react'; | ||
import { | ||
Section, | ||
SectionItem, | ||
CodeFormatter, | ||
SectionButton, | ||
} from '../components/StyledComponents'; | ||
import Loader from '../components/Loader'; | ||
import { EnvContext } from '../context'; | ||
import * as PushAPI from '@pushprotocol/restapi'; | ||
|
||
const GetGroupMemberStatusTest = () => { | ||
const { env } = useContext<any>(EnvContext); | ||
const [isLoading, setLoading] = useState(false); | ||
const [chatId, setChatId] = useState<string>(''); | ||
const [did, setDid] = useState<string>(''); | ||
const [sendResponse, setSendResponse] = useState<any>(''); | ||
|
||
const updateChatId = (e: React.SyntheticEvent<HTMLElement>) => { | ||
setChatId((e.target as HTMLInputElement).value); | ||
}; | ||
|
||
const updateDid = (e: React.SyntheticEvent<HTMLElement>) => { | ||
setDid((e.target as HTMLInputElement).value); | ||
}; | ||
|
||
const testGetGroupMemberStatus = async () => { | ||
try { | ||
setLoading(true); | ||
|
||
const response = await PushAPI.chat.getGroupMemberStatus({ | ||
chatId: chatId, | ||
did: did, | ||
env, | ||
}); | ||
setSendResponse(response); | ||
} catch (e) { | ||
console.error(e); | ||
} finally { | ||
setLoading(false); | ||
} | ||
}; | ||
|
||
return ( | ||
<div> | ||
<h2>Get Group Member Status Test Page</h2> | ||
|
||
<Loader show={isLoading} /> | ||
|
||
<Section> | ||
<SectionItem> | ||
<SectionButton onClick={testGetGroupMemberStatus}>get group member status</SectionButton> | ||
</SectionItem> | ||
<SectionItem> | ||
<label>chatId</label> | ||
<input | ||
type="text" | ||
onChange={updateChatId} | ||
value={chatId} | ||
style={{ width: 400, height: 30 }} | ||
/> | ||
</SectionItem> | ||
<SectionItem> | ||
<label>did</label> | ||
<input | ||
type="text" | ||
onChange={updateDid} | ||
value={did} | ||
style={{ width: 400, height: 30 }} | ||
/> | ||
</SectionItem> | ||
<SectionItem> | ||
<div> | ||
{sendResponse ? ( | ||
<CodeFormatter> | ||
{JSON.stringify(sendResponse, null, 4)} | ||
</CodeFormatter> | ||
) : null} | ||
</div> | ||
</SectionItem> | ||
</Section> | ||
</div> | ||
); | ||
}; | ||
|
||
export default GetGroupMemberStatusTest; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import axios from 'axios'; | ||
import { getAPIBaseUrls } from '../helpers'; | ||
import Constants, { ENV } from '../constants'; | ||
import { GroupAccess, GroupMemberStatus } from '../types'; | ||
import { getUserDID } from './helpers'; | ||
|
||
/** | ||
* GET /v1/chat/groups/:chatId/access/:did | ||
*/ | ||
|
||
export interface GetGroupMemberStatusType { | ||
chatId: string; | ||
did: string; // Decentralized Identifier | ||
env?: ENV; | ||
} | ||
|
||
export const getGroupMemberStatus = async ( | ||
options: GetGroupMemberStatusType | ||
): Promise<GroupMemberStatus> => { | ||
// Replace "any" with the actual response type | ||
const { chatId, did, env = Constants.ENV.PROD } = options || {}; | ||
try { | ||
if (chatId == null || chatId.length === 0) { | ||
throw new Error(`chatId cannot be null or empty`); | ||
} | ||
|
||
if (did == null || did.length === 0) { | ||
throw new Error(`did cannot be null or empty`); | ||
} | ||
|
||
const user = await getUserDID(did, env); | ||
|
||
const API_BASE_URL = getAPIBaseUrls(env); | ||
const requestUrl = `${API_BASE_URL}/v1/chat/groups/${chatId}/members/${user}/status`; | ||
|
||
console.log(requestUrl) | ||
|
||
return axios | ||
.get(requestUrl) | ||
.then((response) => { | ||
return response.data; | ||
}) | ||
.catch((err) => { | ||
if (err?.response?.data) throw new Error(err?.response?.data); | ||
throw new Error(err); | ||
}); | ||
} catch (err) { | ||
console.error( | ||
`[Push SDK] - API - Error - API ${getGroupMemberStatus.name} -: `, | ||
err | ||
); | ||
throw Error( | ||
`[Push SDK] - API - Error - API ${getGroupMemberStatus.name} -: ${err}` | ||
); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.