Fixing branding toggle (#5952)

* Fix form state not saving

* Always show false on toggle if you dont have an active team

* Correct filter
pull/5968/head
sean-brydon 2022-12-09 22:33:49 +00:00 committed by GitHub
parent bc0d83164c
commit ede987ba19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 16 deletions

View File

@ -4,7 +4,7 @@ import { JSONObject } from "superjson/dist/types";
import { z } from "zod";
import { privacyFilteredLocations, LocationObject } from "@calcom/app-store/locations";
import { WEBAPP_URL } from "@calcom/lib/constants";
import { IS_TEAM_BILLING_ENABLED, WEBAPP_URL } from "@calcom/lib/constants";
import { getDefaultEvent, getGroupName, getUsernameList } from "@calcom/lib/defaultEvents";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { parseRecurringEvent } from "@calcom/lib/isRecurringEvent";
@ -157,9 +157,10 @@ async function getUserPageProps(context: GetStaticPropsContext) {
// Check if the user you are logging into has any active teams
const hasActiveTeam =
user.teams.filter((m) => {
if (!IS_TEAM_BILLING_ENABLED) return true;
const metadata = teamMetadataSchema.safeParse(m.team.metadata);
if (metadata.success && metadata.data?.subscriptionId) return false;
return true;
if (metadata.success && metadata.data?.subscriptionId) return true;
return false;
}).length > 0;
return {

View File

@ -14,7 +14,7 @@ import checkLicense from "@calcom/features/ee/common/server/checkLicense";
import ImpersonationProvider from "@calcom/features/ee/impersonation/lib/ImpersonationProvider";
import { hostedCal, isSAMLLoginEnabled } from "@calcom/features/ee/sso/lib/saml";
import { ErrorCode, isPasswordValid, verifyPassword } from "@calcom/lib/auth";
import { APP_NAME, WEBAPP_URL } from "@calcom/lib/constants";
import { APP_NAME, IS_TEAM_BILLING_ENABLED, WEBAPP_URL } from "@calcom/lib/constants";
import { symmetricDecrypt } from "@calcom/lib/crypto";
import { defaultCookies } from "@calcom/lib/default-cookies";
import rateLimit from "@calcom/lib/rateLimit";
@ -125,9 +125,10 @@ const providers: Provider[] = [
// Check if the user you are logging into has any active teams
const hasActiveTeams =
user.teams.filter((m) => {
if (!IS_TEAM_BILLING_ENABLED) return true;
const metadata = teamMetadataSchema.safeParse(m.team.metadata);
if (metadata.success && metadata.data?.subscriptionId) return false;
return true;
if (metadata.success && metadata.data?.subscriptionId) return true;
return false;
}).length > 0;
// authentication success- but does it meet the minimum password requirements?

View File

@ -189,7 +189,7 @@ const AppearanceView = () => {
onCheckedChange={(checked) =>
formMethods.setValue("hideBranding", checked, { shouldDirty: true })
}
checked={value}
checked={!session.data?.user.belongsToActiveTeam ? false : value}
/>
</div>
</div>

View File

@ -34,11 +34,6 @@ const ProfileView = () => {
onError: () => {
router.push("/settings");
},
onSuccess: (team) => {
if (team) {
form.setValue("hideBranding", team.hideBranding);
}
},
}
);
@ -55,10 +50,7 @@ const ProfileView = () => {
form={form}
handleSubmit={(values) => {
if (team) {
const hideBranding = form.getValues("hideBranding");
if (team.hideBranding !== hideBranding) {
mutation.mutate({ id: team.id, hideBranding });
}
mutation.mutate({ id: team.id, hideBranding: values.hideBranding });
}
}}>
<div className="relative flex items-start">
@ -73,6 +65,7 @@ const ProfileView = () => {
<div className="flex-none">
<Controller
control={form.control}
defaultValue={team?.hideBranding ?? false}
name="hideBranding"
render={({ field }) => (
<Switch