Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/app/_components/common/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ type NavbarView = "admin" | "agency" | "driver";

interface NavbarProps {
view: NavbarView;
agencyName?: string;
}

interface NavLinkProps {
Expand All @@ -35,9 +34,14 @@ function NavLink({ href, children }: NavLinkProps) {
);
}

export default function Navbar({ view, agencyName }: NavbarProps) {
export default function Navbar({ view }: NavbarProps) {
const [inviteModalOpen, setInviteModalOpen] = useState(false);
const router = useRouter();

const agencyName = api.organization.getUserOrgName.useQuery(undefined, {
enabled: view === "agency",
}).data;

const { mutate } = api.organization.redirectToDashboard.useMutation({
onSuccess: (data) => {
router.replace(data.redirectUrl);
Expand All @@ -53,7 +57,7 @@ export default function Navbar({ view, agencyName }: NavbarProps) {
color="blue"
transparent={true}
></IconButton>
<Text>{view === "agency" ? `${agencyName ?? "[Agency name]"} Home` : ""}</Text>
<Text>{view === "agency" ? (agencyName ? `${agencyName} Home` : "Loading...") : ""}</Text>
</Group>

{view === "admin" && (
Expand Down
3 changes: 3 additions & 0 deletions src/app/_components/common/profile/profile.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use client";

import { Menu } from "@mantine/core";
import { useQueryClient } from "@tanstack/react-query";
import { useRouter } from "next/navigation";
import Arrow from "@/assets/icons/arrow";
import User from "@/assets/icons/user";
Expand All @@ -13,11 +14,13 @@ import styles from "./Profile.module.scss";
export default function Profile() {
const { data: session } = useSession();
const router = useRouter();
const queryClient = useQueryClient();
function logout() {
authClient
.signOut()
.then(() => {
router.push("/logout");
queryClient.clear();
})
.catch((err) => {
console.error("Logout failed:", err);
Expand Down
23 changes: 23 additions & 0 deletions src/server/api/routers/organizations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,29 @@ import { OrganizationRole, Role } from "@/types/types";
import { nameRegex, passwordSchema, phoneNumberSchema } from "@/types/validation";

export const organizationRouter = createTRPCRouter({
getUserOrgName: protectedProcedure.query(async ({ ctx }) => {
const orgId = ctx.session.session.activeOrganizationId;

if (!orgId) {
throw new TRPCError({
code: "BAD_REQUEST",
message: "No active organization ID set",
});
}

const org = await ctx.db.query.organization.findFirst({
where: (organization, { eq }) => eq(organization.id, orgId),
});

if (!org) {
throw new TRPCError({
code: "NOT_FOUND",
message: "Organization not found in database",
});
}

return org.name;
}),
redirectToDashboard: protectedProcedure.mutation(async ({ ctx }) => {
const userId = ctx.session.user.id;

Expand Down
Loading