Skip to content

Commit 9f8ff71

Browse files
committed
self-review-3
1 parent 1338c63 commit 9f8ff71

File tree

6 files changed

+23
-193
lines changed

6 files changed

+23
-193
lines changed

packages/embeds/embed-core/routing-playground.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
<option value="Sales">Sales</option>
9898
</select>
9999
</form>
100-
<button id="cal-booking-place-routingFormPrerender-submit" data-cal-namespace="routingFormPrerender" data-cal-config='{"cal.embed.pageType":"team.event.booking.slots"}'>Submit</button>
100+
<button id="cal-booking-place-routingFormPrerender-submit" data-cal-namespace="routingFormPrerender" data-cal-config='{"cal.embed.pageType":"team.event.booking.slots", "guests":["[email protected]", "[email protected]"]}'>Submit</button>
101101
<script>
102102
document.getElementById("cal-booking-place-routingFormPrerender-form").addEventListener("input", function prerender(e) {
103103
if (prerender.initiated) return;

packages/embeds/embed-core/src/ModalBox/ModalBox.ts

+3
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ export class ModalBox extends EmbedElement {
155155
onStateLoaded() {
156156
// Hide Loader
157157
this.toggleLoader(false);
158+
// Message is shown either in "failed" or "has-message" state, so we hide it here
159+
this.toggleMessageElement(false);
160+
158161
// Open Modal
159162
this.open();
160163
// Ensure Iframe is fully visible
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
// 2 minutes
1+
// 1 minute
22
export const EMBED_MODAL_IFRAME_FORCE_RELOAD_THRESHOLD_MS = 1 * 60 * 1000;

packages/embeds/embed-core/src/embed-iframe.ts

+16-16
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,12 @@ import type {
1515
PrefillAndIframeAttrsConfig,
1616
} from "./types";
1717
import { useCompatSearchParams } from "./useCompatSearchParams";
18-
import {
19-
buildSearchParamsFromConfig,
20-
fromEntriesWithDuplicateKeys,
21-
isParamValuePresentInUrlSearchParams,
22-
} from "./utils";
18+
import { isParamValuePresentInUrlSearchParams } from "./utils";
2319

20+
// We don't import it from Booker/types because the types from this module are published to npm and we can't import packages that aren't published
2421
type BookerState = "loading" | "selecting_date" | "selecting_time" | "booking";
2522

23+
// Prerendering is a hidden process and we shouldn't really track any events from it unless absolutely necessary
2624
const eventsAllowedInPrerendering = [
2725
// so that Postmessage communication starts
2826
"__iframeReady",
@@ -57,9 +55,10 @@ declare global {
5755
export const embedStore = {
5856
/**
5957
* Tracks whether the prerender has been completed or not.
60-
* prerenderState would be "completed" even after the iframe was switched from isPrerendering to notPrerendering(which happensafter connect)
58+
* NOTE: prerenderState would be "completed" even after the iframe was switched from isPrerendering=true to not Prerendering(which happens after connect)
6159
*/
6260
prerenderState: null as null | "inProgress" | "completed",
61+
6362
// Handles the commands of routing received from parent even when React hasn't initialized and nextRouter isn't available
6463
router: {
6564
/**
@@ -122,6 +121,7 @@ export const embedStore = {
122121
}
123122

124123
function setParamInUrl({ key, value, url }: { key: string; value: string | string[]; url: URL }) {
124+
// Reset and then set the new value, to ensure nothing else remains in value
125125
url.searchParams.delete(key);
126126
const newValueArray = Array.isArray(value) ? value : [value];
127127
newValueArray.forEach((val) => {
@@ -440,10 +440,6 @@ function showPageAsNonEmbed() {
440440
if (document.body.style.background === "transparent") {
441441
document.body.style.background = "";
442442
}
443-
// Ensure that it stays and not reverted by React
444-
runAsap(() => {
445-
resetTransparentBackground();
446-
});
447443
}
448444
}
449445

@@ -497,9 +493,9 @@ const methods = {
497493
parentKnowsIframeReady: (_unused: unknown) => {
498494
log("Method: `parentKnowsIframeReady` called");
499495

500-
runAsap(function tryIfLinkIsReady() {
496+
runAsap(function tryInformingLinkReady() {
501497
if (!isLinkReady()) {
502-
runAsap(tryIfLinkIsReady);
498+
runAsap(tryInformingLinkReady);
503499
return;
504500
}
505501

@@ -518,9 +514,8 @@ const methods = {
518514
*/
519515
connect: function connect(config: PrefillAndIframeAttrsConfig) {
520516
log("Method: connect, requested with params", config);
521-
const searchParams = buildSearchParamsFromConfig(config);
522-
523-
// We reset it to allow informing parent through __dimensionChanged event about possibly updated dimensions
517+
const { iframeAttrs: _1, ...queryParamsFromConfig } = config;
518+
// We reset it to allow informing parent again through `__dimensionChanged` event about possibly updated dimensions with changes in config
524519
embedStore.parentInformedAboutContentHeight = false;
525520

526521
(function tryToConnect() {
@@ -531,7 +526,8 @@ const methods = {
531526

532527
log("Method: connect, prerenderState is completed. Connecting");
533528
connectPreloadedEmbed({
534-
toBeThereParams: fromEntriesWithDuplicateKeys(searchParams.entries()),
529+
// We know after removing iframeAttrs, that it is of this type
530+
toBeThereParams: queryParamsFromConfig as Record<string, string | string[]>,
535531
toRemoveParams: ["preload", "prerender", "cal.skipSlotsFetch"],
536532
});
537533
})();
@@ -825,6 +821,10 @@ export function getEmbedBookerState({
825821
return "slotsPending";
826822
}
827823

824+
/**
825+
* It is meant to sync BookerState to EmbedBookerState
826+
* This function is meant to be called outside useEffect so that we don't wait for React to re-render before doing our work
827+
*/
828828
export function updateEmbedBookerState({
829829
bookerState,
830830
slotsQuery,

packages/embeds/embed-core/src/embed.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,8 @@ export class Cal {
423423
// But it's okay to do it here for now because the embedded calLink also keeps itself hidden till it receives `parentKnowsIframeReady` message(It has it's own reasons for that)
424424
// Once the embedded calLink starts not hiding the document, we should optimize this line to make the iframe visible earlier than this.
425425

426-
// Imp: Don't use visibility:visible as that would make the iframe show even if the host element(A paren tof the iframe) has visibility:hidden set. Just reset the visibility to default
427426
if (!e.detail.data.isPrerendering) {
427+
// Imp: Don't use visibility:visible as that would make the iframe show even if the host element(A paren tof the iframe) has visibility:hidden set. Just reset the visibility to default
428428
this.iframe.style.visibility = "";
429429
}
430430
}

packages/prisma/seed.ts

+1-174
Original file line numberDiff line numberDiff line change
@@ -575,166 +575,6 @@ async function createOrganizationAndAddMembersAndTeams({
575575
});
576576
}
577577
}
578-
579-
return {
580-
orgInDb,
581-
teams: organizationTeams,
582-
};
583-
}
584-
585-
async function createRoutingFormInTeam({
586-
orgOwner,
587-
team,
588-
form,
589-
}: {
590-
orgOwner: { id: number };
591-
team: { id: number };
592-
form: { id: string; name: string };
593-
}) {
594-
const formInDb = await prisma.app_RoutingForms_Form.findUnique({
595-
where: {
596-
id: form.id,
597-
},
598-
});
599-
600-
if (formInDb) {
601-
console.log(`Skipping Routing Form - Form Seed, "Seeded Form - Pro" already exists`);
602-
return;
603-
}
604-
605-
const multiSelectLegacyFieldId = "d2292635-9f12-17b1-9153-c3a854649182";
606-
await prisma.app_RoutingForms_Form.create({
607-
data: {
608-
id: form.id,
609-
routes: [
610-
{
611-
id: "8a898988-89ab-4cde-b012-31823f708642",
612-
action: { type: "eventTypeRedirectUrl", value: "team/team1/team1-event-1" },
613-
queryValue: {
614-
id: "8a898988-89ab-4cde-b012-31823f708642",
615-
type: "group",
616-
children1: {
617-
"8988bbb8-0123-4456-b89a-b1823f70c5ff": {
618-
type: "rule",
619-
properties: {
620-
field: "c1296635-9f12-47b1-8153-c3a854649182",
621-
value: ["event-routing"],
622-
operator: "equal",
623-
valueSrc: ["value"],
624-
valueType: ["text"],
625-
},
626-
},
627-
},
628-
},
629-
},
630-
{
631-
id: "aa8aaba9-cdef-4012-b456-71823f70f7ef",
632-
action: { type: "customPageMessage", value: "Custom Page Result" },
633-
queryValue: {
634-
id: "aa8aaba9-cdef-4012-b456-71823f70f7ef",
635-
type: "group",
636-
children1: {
637-
"b99b8a89-89ab-4cde-b012-31823f718ff5": {
638-
type: "rule",
639-
properties: {
640-
field: "c1296635-9f12-47b1-8153-c3a854649182",
641-
value: ["custom-page"],
642-
operator: "equal",
643-
valueSrc: ["value"],
644-
valueType: ["text"],
645-
},
646-
},
647-
},
648-
},
649-
},
650-
{
651-
id: "a8ba9aab-4567-489a-bcde-f1823f71b4ad",
652-
action: { type: "externalRedirectUrl", value: "https://cal.com" },
653-
queryValue: {
654-
id: "a8ba9aab-4567-489a-bcde-f1823f71b4ad",
655-
type: "group",
656-
children1: {
657-
"998b9b9a-0123-4456-b89a-b1823f7232b9": {
658-
type: "rule",
659-
properties: {
660-
field: "c1296635-9f12-47b1-8153-c3a854649182",
661-
value: ["external-redirect"],
662-
operator: "equal",
663-
valueSrc: ["value"],
664-
valueType: ["text"],
665-
},
666-
},
667-
},
668-
},
669-
},
670-
{
671-
id: "aa8ba8b9-0123-4456-b89a-b182623406d8",
672-
action: { type: "customPageMessage", value: "Multiselect chosen" },
673-
queryValue: {
674-
id: "aa8ba8b9-0123-4456-b89a-b182623406d8",
675-
type: "group",
676-
children1: {
677-
"b98a8abb-cdef-4012-b456-718262343d27": {
678-
type: "rule",
679-
properties: {
680-
field: multiSelectLegacyFieldId,
681-
value: [["Option-2"]],
682-
operator: "multiselect_equals",
683-
valueSrc: ["value"],
684-
valueType: ["multiselect"],
685-
},
686-
},
687-
},
688-
},
689-
},
690-
{
691-
id: "898899aa-4567-489a-bcde-f1823f708646",
692-
action: { type: "customPageMessage", value: "Fallback Message" },
693-
isFallback: true,
694-
queryValue: { id: "898899aa-4567-489a-bcde-f1823f708646", type: "group" },
695-
},
696-
],
697-
fields: [
698-
{ id: "c1296635-9f12-47b1-8153-c3a854649182", type: "text", label: "Test field", required: true },
699-
{
700-
id: multiSelectLegacyFieldId,
701-
type: "multiselect",
702-
label: "Multi Select(with legacy `selectText`)",
703-
identifier: "multi",
704-
selectText: "Option-1\nOption-2",
705-
required: false,
706-
},
707-
{
708-
id: "d3292635-9f12-17b1-9153-c3a854649182",
709-
type: "multiselect",
710-
label: "Multi Select",
711-
identifier: "multi",
712-
options: [
713-
{
714-
id: "d1234635-9f12-17b1-9153-c3a854649182",
715-
label: "Option-1",
716-
},
717-
{
718-
id: "d1235635-9f12-17b1-9153-c3a854649182",
719-
label: "Option-2",
720-
},
721-
],
722-
required: false,
723-
},
724-
],
725-
team: {
726-
connect: {
727-
id: team.id,
728-
},
729-
},
730-
name: form.name,
731-
user: {
732-
connect: {
733-
id: orgOwner.id,
734-
},
735-
},
736-
},
737-
});
738578
}
739579

740580
async function main() {
@@ -1328,7 +1168,7 @@ async function main() {
13281168
]
13291169
);
13301170

1331-
const { orgInDb: acmeOrgInDb, teams: acmeTeams } = await createOrganizationAndAddMembersAndTeams({
1171+
await createOrganizationAndAddMembersAndTeams({
13321172
org: {
13331173
orgData: {
13341174
name: "Acme Inc",
@@ -1425,19 +1265,6 @@ async function main() {
14251265
],
14261266
});
14271267

1428-
await createRoutingFormInTeam({
1429-
orgOwner: {
1430-
id: acmeOrgInDb.members[0].id,
1431-
},
1432-
team: {
1433-
id: acmeTeams[0].id,
1434-
},
1435-
form: {
1436-
id: "acme-routing-form-id-1",
1437-
name: "Team-1Routing Form-1",
1438-
},
1439-
});
1440-
14411268
await createOrganizationAndAddMembersAndTeams({
14421269
org: {
14431270
orgData: {

0 commit comments

Comments
 (0)