* remove event type requires confirmation * allow sms sending also for team (frontend) * allow text to attendee for team (backend) * add rate limiting for SMS (WIP) * add functionality to lock and unlock SMS sending (+admin UI view) * rename to smsLockState * add ability to lock users and teams * don't send sms if locked * add missing imports * fix rate limit namespace * add translation * fix type error * remove prop from UsersTable * add smsLockState to buildUser * code clean up * create seperate sms rate limit function * fix type error * add missing userId and teamId to sendSMS * code improvements * add User Team type * fix marking as reviewed * check monthly sms limit only for user * don't lock orgs * fix type error * fix avatars * fix type error * fix type error * fix type error --------- Co-authored-by: CarinaWolli <wollencarina@gmail.com> Co-authored-by: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com> Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com>
83 lines
2.4 KiB
TypeScript
83 lines
2.4 KiB
TypeScript
"use client";
|
|
|
|
import UsersTable from "@pages/settings/admin/lockedSMS/UsersTable";
|
|
import { useState } from "react";
|
|
|
|
import { trpc } from "@calcom/trpc";
|
|
import { Button, Meta, TextField, showToast } from "@calcom/ui";
|
|
|
|
export default function LockedSMSView() {
|
|
const [username, setUsername] = useState("");
|
|
const [teamSlug, setTeamSlug] = useState("");
|
|
|
|
const utils = trpc.useContext();
|
|
|
|
const mutation = trpc.viewer.admin.setSMSLockState.useMutation({
|
|
onSuccess: (data) => {
|
|
if (data) {
|
|
showToast(`${data.name} successfully ${data.locked ? "locked" : "unlocked"}`, "success");
|
|
}
|
|
utils.viewer.admin.getSMSLockStateTeamsUsers.invalidate();
|
|
},
|
|
onError: (error) => {
|
|
showToast(`${error}`, "error");
|
|
utils.viewer.admin.getSMSLockStateTeamsUsers.invalidate();
|
|
},
|
|
});
|
|
|
|
function setSMSLockState({ userId, teamId, lock }: { userId?: number; teamId?: number; lock: boolean }) {
|
|
mutation.mutate({
|
|
userId,
|
|
teamId,
|
|
lock,
|
|
});
|
|
}
|
|
|
|
return (
|
|
<div>
|
|
<Meta title="lockedSMS" description="Lock or unlock SMS sending for users" />
|
|
<div className="mb-4 flex w-full items-center justify-between space-x-2 rtl:space-x-reverse">
|
|
<div className="flex">
|
|
<TextField
|
|
name="Lock User"
|
|
placeholder="username"
|
|
defaultValue=""
|
|
onChange={(event) => setUsername(event.target.value)}
|
|
value={username}
|
|
/>
|
|
<Button
|
|
type="submit"
|
|
className="ml-2 mt-5"
|
|
onClick={() => {
|
|
mutation.mutate({ username, lock: true });
|
|
utils.viewer.admin.getSMSLockStateTeamsUsers.invalidate();
|
|
}}>
|
|
Lock User
|
|
</Button>
|
|
</div>
|
|
<div className="flex">
|
|
<TextField
|
|
name="Lock Team"
|
|
placeholder="team slug"
|
|
defaultValue=""
|
|
onChange={(event) => {
|
|
setTeamSlug(event.target.value);
|
|
}}
|
|
value={teamSlug}
|
|
/>
|
|
<Button
|
|
type="submit"
|
|
className="ml-2 mt-5"
|
|
onClick={() => {
|
|
mutation.mutate({ teamSlug, lock: true });
|
|
utils.viewer.admin.getSMSLockStateTeamsUsers.invalidate();
|
|
}}>
|
|
Lock Team
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
<UsersTable setSMSLockState={setSMSLockState} />
|
|
</div>
|
|
);
|
|
}
|