2023-03-25 00:59:04 +00:00
|
|
|
import { trpc } from "@calcom/trpc/react";
|
|
|
|
import type { RouterOutputs } from "@calcom/trpc/react";
|
2023-04-13 02:10:23 +00:00
|
|
|
import { Badge, List, ListItem, ListItemText, ListItemTitle, Switch, showToast } from "@calcom/ui";
|
2023-03-25 00:59:04 +00:00
|
|
|
|
|
|
|
export const FlagAdminList = () => {
|
|
|
|
const [data] = trpc.viewer.features.list.useSuspenseQuery();
|
|
|
|
return (
|
|
|
|
<List roundContainer noBorderTreatment>
|
|
|
|
{data.map((flag) => (
|
|
|
|
<ListItem key={flag.slug} rounded={false}>
|
|
|
|
<div className="flex flex-1 flex-col">
|
|
|
|
<ListItemTitle component="h3">
|
|
|
|
{flag.slug}
|
|
|
|
|
2023-04-13 02:10:23 +00:00
|
|
|
<Badge variant="green">{flag.type?.replace("_", " ")}</Badge>
|
2023-03-25 00:59:04 +00:00
|
|
|
</ListItemTitle>
|
|
|
|
<ListItemText component="p">{flag.description}</ListItemText>
|
|
|
|
</div>
|
|
|
|
<div className="flex py-2">
|
|
|
|
<FlagToggle flag={flag} />
|
|
|
|
</div>
|
|
|
|
</ListItem>
|
|
|
|
))}
|
|
|
|
</List>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
type Flag = RouterOutputs["viewer"]["features"]["list"][number];
|
|
|
|
|
|
|
|
const FlagToggle = (props: { flag: Flag }) => {
|
|
|
|
const {
|
|
|
|
flag: { slug, enabled },
|
|
|
|
} = props;
|
|
|
|
const utils = trpc.useContext();
|
2023-07-25 22:00:21 +00:00
|
|
|
const mutation = trpc.viewer.admin.toggleFeatureFlag.useMutation({
|
2023-03-25 00:59:04 +00:00
|
|
|
onSuccess: () => {
|
2023-04-13 02:10:23 +00:00
|
|
|
showToast("Flags successfully updated", "success");
|
2023-03-25 00:59:04 +00:00
|
|
|
utils.viewer.features.list.invalidate();
|
|
|
|
utils.viewer.features.map.invalidate();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
return (
|
|
|
|
<Switch
|
|
|
|
defaultChecked={enabled}
|
|
|
|
onCheckedChange={(checked) => {
|
|
|
|
mutation.mutate({ slug, enabled: checked });
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|