Added redemptions & redeemable actions. Fixed a few bugs.
This commit is contained in:
@@ -13,110 +13,104 @@ import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem } from "
|
||||
|
||||
|
||||
const AdminProfile = () => {
|
||||
const session = useSession();
|
||||
const [impersonation, setImpersonation] = useState<string | null>(null)
|
||||
const [open, setOpen] = useState(false)
|
||||
const session = useSession();
|
||||
const [impersonation, setImpersonation] = useState<string | null>(null)
|
||||
const [open, setOpen] = useState(false)
|
||||
const [users, setUsers] = useState<User[]>([])
|
||||
|
||||
const [users, setUsers] = useState<User[]>([])
|
||||
useEffect(() => {
|
||||
const fetch = async (userId: string | undefined) => {
|
||||
if (!userId) return
|
||||
|
||||
useEffect(() => {
|
||||
const fetch = async (userId: string | undefined) => {
|
||||
if (!userId) return
|
||||
await axios.get("/api/users?id=" + userId)
|
||||
.then(u => setImpersonation(u.data?.name))
|
||||
}
|
||||
|
||||
await axios.get<User>("/api/users?id=" + userId)
|
||||
.then(u => {
|
||||
setImpersonation(u.data?.name)
|
||||
})
|
||||
const fetchUsers = async () => {
|
||||
await axios.get<User[]>("/api/users")
|
||||
.then((u) => {
|
||||
setUsers(u.data.filter(x => x.id != session.data?.user.id))
|
||||
})
|
||||
}
|
||||
|
||||
fetch(session?.data?.user?.impersonation?.id)
|
||||
fetchUsers()
|
||||
}, [])
|
||||
|
||||
const onImpersonationChange = async (userId: string, name: string) => {
|
||||
console.log("IMPERSONATION", impersonation)
|
||||
if (impersonation) {
|
||||
if (impersonation == name) {
|
||||
await axios.delete("/api/account/impersonate")
|
||||
.then(() => {
|
||||
setImpersonation(null)
|
||||
window.location.reload()
|
||||
})
|
||||
} else {
|
||||
await axios.put("/api/account/impersonate", { targetId: userId })
|
||||
.then(() => {
|
||||
setImpersonation(name)
|
||||
window.location.reload()
|
||||
})
|
||||
}
|
||||
} else {
|
||||
await axios.post("/api/account/impersonate", { targetId: userId })
|
||||
.then(() => {
|
||||
setImpersonation(name)
|
||||
window.location.reload()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
console.log(session)
|
||||
fetch(session?.data?.user?.impersonation?.id)
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
const fetchUsers = async () => {
|
||||
await axios.get<User[]>("/api/users")
|
||||
.then((u) => {
|
||||
setUsers(u.data.filter(x => x.id != session.data?.user.id))
|
||||
})
|
||||
}
|
||||
|
||||
fetchUsers()
|
||||
}, [])
|
||||
|
||||
const onImpersonationChange = async (userId: string, name: string) => {
|
||||
if (impersonation) {
|
||||
if (impersonation == session.data?.user.impersonation?.name) {
|
||||
await axios.delete("/api/account/impersonate")
|
||||
.then(() => {
|
||||
setImpersonation(null)
|
||||
window.location.reload()
|
||||
})
|
||||
} else {
|
||||
await axios.put("/api/account/impersonate", { targetId: userId })
|
||||
.then(() => {
|
||||
setImpersonation(name)
|
||||
window.location.reload()
|
||||
})
|
||||
}
|
||||
} else {
|
||||
await axios.post("/api/account/impersonate", { targetId: userId })
|
||||
.then(() => {
|
||||
setImpersonation(name)
|
||||
window.location.reload()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={"px-5 py-3 rounded-md bg-red-300 overflow-hidden wrap my-[10px] flex flex-grow flex-col gap-y-3"}>
|
||||
<div>
|
||||
<p className="text-xs text-gray-200">Role:</p>
|
||||
<p>{session?.data?.user?.role}</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-xs text-gray-200">Impersonation:</p>
|
||||
<Popover open={open} onOpenChange={setOpen}>
|
||||
<PopoverTrigger asChild>
|
||||
<Button
|
||||
variant="outline"
|
||||
role="combobox"
|
||||
aria-expanded={open}
|
||||
className="flex flex-grow justify-between text-xs">
|
||||
{impersonation ? impersonation : "Select a user"}
|
||||
<ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent className="w-[200px] p-0">
|
||||
<Command>
|
||||
<CommandInput placeholder="Search users by name" />
|
||||
<CommandEmpty>No voices found.</CommandEmpty>
|
||||
<CommandGroup>
|
||||
{users.map((user) => (
|
||||
<CommandItem
|
||||
key={user.id}
|
||||
value={user.name ?? undefined}
|
||||
onSelect={(currentValue) => {
|
||||
onImpersonationChange(user.id, user.name ?? "")
|
||||
setOpen(false)
|
||||
}}
|
||||
>
|
||||
<Check
|
||||
className={cn(
|
||||
"mr-2 h-4 w-4",
|
||||
user.name == impersonation ? "opacity-100" : "opacity-0"
|
||||
)}
|
||||
/>
|
||||
{user.name}
|
||||
</CommandItem>
|
||||
))}
|
||||
</CommandGroup>
|
||||
</Command>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
return (
|
||||
<div className={"px-5 py-3 rounded-md bg-red-300 overflow-hidden wrap my-[10px] flex flex-grow flex-col gap-y-3"}>
|
||||
<div>
|
||||
<p className="text-xs text-gray-200">Role:</p>
|
||||
<p>{session?.data?.user?.role}</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-xs text-gray-200">Impersonation:</p>
|
||||
<Popover open={open} onOpenChange={setOpen}>
|
||||
<PopoverTrigger asChild>
|
||||
<Button
|
||||
variant="outline"
|
||||
role="combobox"
|
||||
aria-expanded={open}
|
||||
className="flex flex-grow justify-between text-xs">
|
||||
{impersonation ? impersonation : "Select a user"}
|
||||
<ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent className="w-[200px] p-0">
|
||||
<Command>
|
||||
<CommandInput placeholder="Search users by name" />
|
||||
<CommandEmpty>No voices found.</CommandEmpty>
|
||||
<CommandGroup>
|
||||
{users.map((user) => (
|
||||
<CommandItem
|
||||
key={user.id}
|
||||
value={user.name ?? undefined}
|
||||
onSelect={(currentValue) => {
|
||||
onImpersonationChange(user.id, user.name ?? "")
|
||||
setOpen(false)
|
||||
}}
|
||||
>
|
||||
<Check
|
||||
className={cn(
|
||||
"mr-2 h-4 w-4",
|
||||
user.name == impersonation ? "opacity-100" : "opacity-0"
|
||||
)}
|
||||
/>
|
||||
{user.name}
|
||||
</CommandItem>
|
||||
))}
|
||||
</CommandGroup>
|
||||
</Command>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
export default AdminProfile;
|
||||
@@ -47,6 +47,17 @@ const SettingsNavigation = async () => {
|
||||
</Link>
|
||||
</li>
|
||||
|
||||
<li className="text-xs text-gray-200">
|
||||
Twitch
|
||||
</li>
|
||||
<li className="">
|
||||
<Link href={"/settings/redemptions"}>
|
||||
<Button variant="ghost" className="w-full text-lg">
|
||||
Channel Redemptions
|
||||
</Button>
|
||||
</Link>
|
||||
</li>
|
||||
|
||||
<li className="text-xs text-gray-200">
|
||||
API
|
||||
</li>
|
||||
|
||||
@@ -22,7 +22,7 @@ const UserProfile = () => {
|
||||
const fetchData = async () => {
|
||||
if (user) return
|
||||
|
||||
var userData = (await axios.get("/api/account")).data
|
||||
let userData = (await axios.get("/api/account")).data
|
||||
setUser(userData)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user