mirror of
https://github.com/hex248/sprint.git
synced 2026-02-07 18:23:03 +00:00
update user state variable on change
This commit is contained in:
@@ -23,7 +23,9 @@ import { ResizablePanel, ResizablePanelGroup, ResizableSeparator } from "@/compo
|
||||
import { issue, organisation, project } from "@/lib/server";
|
||||
|
||||
function Index() {
|
||||
const user = JSON.parse(localStorage.getItem("user") || "{}") as UserRecord;
|
||||
const userData = JSON.parse(localStorage.getItem("user") || "{}") as UserRecord;
|
||||
|
||||
const [user, setUser] = useState<UserRecord>(userData);
|
||||
|
||||
const organisationsRef = useRef(false);
|
||||
const [organisations, setOrganisations] = useState<OrganisationResponse[]>([]);
|
||||
@@ -35,6 +37,11 @@ function Index() {
|
||||
const [issues, setIssues] = useState<IssueResponse[]>([]);
|
||||
const [selectedIssue, setSelectedIssue] = useState<IssueResponse | null>(null);
|
||||
|
||||
const refetchUser = async () => {
|
||||
const userData = JSON.parse(localStorage.getItem("user") || "{}") as UserRecord;
|
||||
setUser(userData);
|
||||
};
|
||||
|
||||
const refetchOrganisations = async (options?: { selectOrganisationId?: number }) => {
|
||||
try {
|
||||
await organisation.byUser({
|
||||
@@ -220,7 +227,11 @@ function Index() {
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align={"end"}>
|
||||
<DropdownMenuItem asChild className="flex items-end justify-end">
|
||||
<AccountDialog />
|
||||
<AccountDialog
|
||||
onUpdate={async () => {
|
||||
refetchUser();
|
||||
}}
|
||||
/>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem asChild className="flex items-end justify-end">
|
||||
<OrganisationsDialog
|
||||
|
||||
@@ -8,7 +8,7 @@ import { Label } from "@/components/ui/label";
|
||||
import { UploadAvatar } from "@/components/upload-avatar";
|
||||
import { user } from "@/lib/server";
|
||||
|
||||
function AccountDialog({ trigger }: { trigger?: ReactNode }) {
|
||||
function AccountDialog({ onUpdate, trigger }: { onUpdate?: () => void; trigger?: ReactNode }) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const [name, setName] = useState("");
|
||||
const [username, setUsername] = useState("");
|
||||
@@ -57,7 +57,8 @@ function AccountDialog({ trigger }: { trigger?: ReactNode }) {
|
||||
setError("");
|
||||
localStorage.setItem("user", JSON.stringify(data));
|
||||
setPassword("");
|
||||
window.location.reload();
|
||||
onUpdate?.();
|
||||
setOpen(false);
|
||||
},
|
||||
onError: (errorMessage) => {
|
||||
setError(errorMessage);
|
||||
|
||||
Reference in New Issue
Block a user