import * as React from "react";
import { useTranslation } from "react-i18next";
import { UserRole } from "@shared/types";
import User from "~/models/User";
import ConfirmationDialog from "~/components/ConfirmationDialog";
import Input from "~/components/Input";
import useStores from "~/hooks/useStores";
type Props = {
user: User;
onSubmit: () => void;
};
export function UserChangeToViewerDialog({ user, onSubmit }: Props) {
const { t } = useTranslation();
const { users } = useStores();
const handleSubmit = async () => {
await users.demote(user, UserRole.Viewer);
onSubmit();
};
return (
{t(
"Are you sure you want to make {{ userName }} a read-only viewer? They will not be able to edit any content",
{
userName: user.name,
}
)}
.
);
}
export function UserChangeToMemberDialog({ user, onSubmit }: Props) {
const { t } = useTranslation();
const { users } = useStores();
const handleSubmit = async () => {
await users.demote(user, UserRole.Member);
onSubmit();
};
return (
{t("Are you sure you want to make {{ userName }} a member?", {
userName: user.name,
})}
);
}
export function UserDeleteDialog({ user, onSubmit }: Props) {
const { t } = useTranslation();
const handleSubmit = async () => {
await user.delete();
onSubmit();
};
return (
{t(
"Are you sure you want to permanently delete {{ userName }}? This operation is unrecoverable, consider suspending the user instead.",
{
userName: user.name,
}
)}
);
}
export function UserChangeToAdminDialog({ user, onSubmit }: Props) {
const { t } = useTranslation();
const { users } = useStores();
const handleSubmit = async () => {
await users.promote(user);
onSubmit();
};
return (
{t(
"Are you sure you want to make {{ userName }} an admin? Admins can modify team and billing information.",
{
userName: user.name,
}
)}
);
}
export function UserSuspendDialog({ user, onSubmit }: Props) {
const { t } = useTranslation();
const { users } = useStores();
const handleSubmit = async () => {
await users.suspend(user);
onSubmit();
};
return (
{t(
"Are you sure you want to suspend {{ userName }}? Suspended users will be prevented from logging in.",
{
userName: user.name,
}
)}
);
}
export function UserChangeNameDialog({ user, onSubmit }: Props) {
const { t } = useTranslation();
const [name, setName] = React.useState(user.name);
const handleSubmit = async () => {
await user.save({ name });
onSubmit();
};
const handleChange = (ev: React.ChangeEvent) => {
setName(ev.target.value);
};
return (
);
}