-
-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: show channel joining banner on mobile
- Loading branch information
1 parent
3d24022
commit 9d12596
Showing
2 changed files
with
74 additions
and
7 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
51 changes: 51 additions & 0 deletions
51
mobile/src/components/features/chat-space/JoinChannelButton.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,51 @@ | ||
import { ChannelListItem } from "@/utils/channel/ChannelListProvider" | ||
import { useFrappeCreateDoc, useSWRConfig } from "frappe-react-sdk" | ||
import { Box, Flex, Text, Button } from "@radix-ui/themes" | ||
import { ErrorBanner } from "@/components/layout" | ||
import { useContext } from "react" | ||
import { UserContext } from "@/utils/auth/UserProvider" | ||
interface JoinChannelBoxProps { | ||
channelData: ChannelListItem, | ||
} | ||
|
||
const JoinChannelButton = ({ channelData }: JoinChannelBoxProps) => { | ||
|
||
const { currentUser } = useContext(UserContext) | ||
const { mutate } = useSWRConfig() | ||
const { createDoc, error, loading } = useFrappeCreateDoc() | ||
|
||
const joinChannel = async () => { | ||
return createDoc('Raven Channel Member', { | ||
channel_id: channelData?.name, | ||
user_id: currentUser | ||
}).then(() => { | ||
|
||
mutate(`raven.api.chat.get_channel_members.${channelData.name}`) | ||
}) | ||
} | ||
|
||
return ( | ||
<Box> | ||
<Flex | ||
direction='column' | ||
align='center' | ||
gap='3' | ||
className="rounded-md bg-surface animate-fadein" | ||
p='4' | ||
pb='8'> | ||
<ErrorBanner error={error} /> | ||
<Text as='span'>You are not a member of this channel.</Text> | ||
<Button | ||
onClick={joinChannel} | ||
size='3' | ||
loading={loading}> | ||
<span className="inline-flex gap-1">Join | ||
"{channelData.channel_name}" | ||
</span> | ||
</Button> | ||
</Flex> | ||
</Box> | ||
) | ||
} | ||
|
||
export default JoinChannelButton |