feat: change channel visibility
This commit is contained in:
@@ -42,6 +42,13 @@ export const channelApi = createApi({
|
|||||||
body: data
|
body: data
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
|
changeChannelType: builder.mutation<number, { is_public: boolean, id: number }>({
|
||||||
|
query: ({ id, is_public }) => ({
|
||||||
|
url: `group/${id}/change_type`,
|
||||||
|
method: "POST",
|
||||||
|
body: { is_public }
|
||||||
|
})
|
||||||
|
}),
|
||||||
updateChannel: builder.mutation<void, ChannelDTO>({
|
updateChannel: builder.mutation<void, ChannelDTO>({
|
||||||
query: ({ id, ...data }) => ({
|
query: ({ id, ...data }) => ({
|
||||||
url: `group/${id}`,
|
url: `group/${id}`,
|
||||||
@@ -186,6 +193,7 @@ export const channelApi = createApi({
|
|||||||
});
|
});
|
||||||
|
|
||||||
export const {
|
export const {
|
||||||
|
useChangeChannelTypeMutation,
|
||||||
useLazyLeaveChannelQuery,
|
useLazyLeaveChannelQuery,
|
||||||
useLazyCreateInviteLinkQuery,
|
useLazyCreateInviteLinkQuery,
|
||||||
useCreateInviteLinkQuery,
|
useCreateInviteLinkQuery,
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { useState, useId, FC } from "react";
|
|||||||
import styled from "styled-components";
|
import styled from "styled-components";
|
||||||
|
|
||||||
const StyledForm = styled.form`
|
const StyledForm = styled.form`
|
||||||
|
width: 100%;
|
||||||
> .option {
|
> .option {
|
||||||
&:not(:last-child) {
|
&:not(:last-child) {
|
||||||
margin-bottom: 8px;
|
margin-bottom: 8px;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { useState, useEffect, ChangeEvent } from "react";
|
|||||||
import styled from "styled-components";
|
import styled from "styled-components";
|
||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
import {
|
import {
|
||||||
|
useChangeChannelTypeMutation,
|
||||||
useGetChannelQuery,
|
useGetChannelQuery,
|
||||||
useUpdateChannelMutation,
|
useUpdateChannelMutation,
|
||||||
useUpdateIconMutation
|
useUpdateIconMutation
|
||||||
@@ -9,6 +10,7 @@ import {
|
|||||||
import AvatarUploader from "../../common/component/AvatarUploader";
|
import AvatarUploader from "../../common/component/AvatarUploader";
|
||||||
import Input from "../../common/component/styled/Input";
|
import Input from "../../common/component/styled/Input";
|
||||||
import Label from "../../common/component/styled/Label";
|
import Label from "../../common/component/styled/Label";
|
||||||
|
import Radio from "../../common/component/styled/Radio";
|
||||||
import Textarea from "../../common/component/styled/Textarea";
|
import Textarea from "../../common/component/styled/Textarea";
|
||||||
import SaveTip from "../../common/component/SaveTip";
|
import SaveTip from "../../common/component/SaveTip";
|
||||||
import channelIcon from "../../assets/icons/channel.svg?url";
|
import channelIcon from "../../assets/icons/channel.svg?url";
|
||||||
@@ -41,6 +43,7 @@ const StyledWrapper = styled.div`
|
|||||||
background-position-y: 8px;
|
background-position-y: 8px;
|
||||||
background-repeat: no-repeat;
|
background-repeat: no-repeat;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
@@ -56,6 +59,7 @@ export default function Overview({ id = 0 }) {
|
|||||||
const [values, setValues] = useState<Channel>();
|
const [values, setValues] = useState<Channel>();
|
||||||
const [updateChannelIcon] = useUpdateIconMutation();
|
const [updateChannelIcon] = useUpdateIconMutation();
|
||||||
const [updateChannel, { isSuccess: updated }] = useUpdateChannelMutation();
|
const [updateChannel, { isSuccess: updated }] = useUpdateChannelMutation();
|
||||||
|
const [changeChannelType, { isSuccess: changeTypeSuccess }] = useChangeChannelTypeMutation();
|
||||||
const handleUpdate = () => {
|
const handleUpdate = () => {
|
||||||
if (!values) return;
|
if (!values) return;
|
||||||
const { name, description } = values;
|
const { name, description } = values;
|
||||||
@@ -103,6 +107,11 @@ export default function Overview({ id = 0 }) {
|
|||||||
refetch();
|
refetch();
|
||||||
}
|
}
|
||||||
}, [updated]);
|
}, [updated]);
|
||||||
|
useEffect(() => {
|
||||||
|
if (changeTypeSuccess) {
|
||||||
|
toast.success("Change channel visibility successfully!");
|
||||||
|
}
|
||||||
|
}, [changeTypeSuccess]);
|
||||||
|
|
||||||
if (!values || !id) return null;
|
if (!values || !id) return null;
|
||||||
const { name, description } = values;
|
const { name, description } = values;
|
||||||
@@ -138,6 +147,19 @@ export default function Overview({ id = 0 }) {
|
|||||||
placeholder="Let everyone know how to use this channel."
|
placeholder="Let everyone know how to use this channel."
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
{!readOnly && <div className="input">
|
||||||
|
<Label htmlFor="desc">Channel Visibility</Label>
|
||||||
|
<Radio
|
||||||
|
options={["Public", "Private"]}
|
||||||
|
values={["true", "false"]}
|
||||||
|
value={String(channel.is_public)}
|
||||||
|
onChange={(v: string) => {
|
||||||
|
// console.log("wtff", typeof v, v);
|
||||||
|
changeChannelType({ is_public: v.toLowerCase() === 'true', id });
|
||||||
|
// handleGuestToggle(v);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>}
|
||||||
</div>
|
</div>
|
||||||
{changed && <SaveTip saveHandler={handleUpdate} resetHandler={handleReset} />}
|
{changed && <SaveTip saveHandler={handleUpdate} resetHandler={handleReset} />}
|
||||||
</StyledWrapper>
|
</StyledWrapper>
|
||||||
|
|||||||
Reference in New Issue
Block a user