fix: fix isAcessible query join/filter and clear sub org query cache when org changes

This commit is contained in:
Scott Wilson
2025-10-20 18:18:21 -07:00
parent d7bfa38499
commit 9bb0e2c401
3 changed files with 15 additions and 12 deletions

View File

@@ -172,14 +172,16 @@ export const orgDALFactory = (db: TDbClient) => {
.select(selectAllTableCols(TableName.Organization));
if (dto.isAccessible) {
void query.leftJoin(`${TableName.Membership}`, (qb) => {
void qb.on(`${TableName.Membership}.scope`, AccessScope.Organization);
if (dto.actorType === ActorType.IDENTITY) {
void qb.andOn(`${TableName.Membership}.actorIdentityId`, dto.actorId);
} else {
void qb.andOn(`${TableName.Membership}.actorUserId`, dto.actorId);
}
});
void query
.leftJoin(`${TableName.Membership}`, `${TableName.Membership}.scopeOrgId`, `${TableName.Organization}.id`)
.where((qb) => {
void qb.where(`${TableName.Membership}.scope`, AccessScope.Organization);
if (dto.actorType === ActorType.IDENTITY) {
void qb.andWhere(`${TableName.Membership}.actorIdentityId`, dto.actorId);
} else {
void qb.andWhere(`${TableName.Membership}.actorUserId`, dto.actorId);
}
});
}
if (dto.limit) void query.limit(dto.limit);
if (dto.offset) void query.offset(dto.offset);

View File

@@ -134,13 +134,13 @@ export const Navbar = () => {
const { subscription } = useSubscription();
const { currentOrg, isSubOrganization } = useOrganization();
console.log("current", currentOrg, isSubOrganization);
const [showAdminsModal, setShowAdminsModal] = useState(false);
const [showSubOrgForm, setShowSubOrgForm] = useState(false);
const [showCardDeclinedModal, setShowCardDeclinedModal] = useState(false);
const subOrgQuery = subOrganizationsQuery.list({ limit: 500, isAccessible: true });
const { data: subOrganizations = [] } = useQuery({
...subOrganizationsQuery.list({ limit: 500, isAccessible: true }),
...subOrgQuery,
enabled: Boolean(subscription.subOrganization)
});
@@ -183,6 +183,7 @@ export const Navbar = () => {
}
await router.invalidate();
await navigateUserToOrg(navigate, orgId);
queryClient.removeQueries({ queryKey: subOrgQuery.queryKey });
};
const { mutateAsync } = useGetOrgTrialUrl();

View File

@@ -7,7 +7,7 @@ import { z } from "zod";
import { createNotification } from "@app/components/notifications";
import { Button, FormControl, Input } from "@app/components/v2";
import { useCreateSubOrganization } from "@app/hooks/api";
import { GenericResourceNameSchema, slugSchema } from "@app/lib/schemas";
import { slugSchema } from "@app/lib/schemas";
type ContentProps = {
onClose: () => void;