@iblai/web-utils 1.3.2 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -4,6 +4,7 @@ var React = require('react');
4
4
  var dataLayer = require('@iblai/data-layer');
5
5
  var jsxRuntime = require('react/jsx-runtime');
6
6
  var iblaiApi = require('@iblai/iblai-api');
7
+ require('react-dom');
7
8
  var axios = require('axios');
8
9
 
9
10
  function _interopNamespaceDefault(e) {
@@ -552,6 +553,13 @@ const MENTOR_AI_CONFIG = {
552
553
  description: "Display the accessibility menu in the mentor platform.",
553
554
  type: "boolean",
554
555
  },
556
+ {
557
+ slug: "persistent_chat_input_label",
558
+ label: "Persistent Chat Input Label",
559
+ defaultValue: false,
560
+ description: "Show a visible, persistent label above the chat input. When off, the label is available to screen readers only.",
561
+ type: "boolean",
562
+ },
555
563
  {
556
564
  slug: "mentor_include_community_mentors",
557
565
  label: "Community Mentors",
@@ -3513,6 +3521,7 @@ function TenantProvider({ children, fallback, onAuthSuccess, onAuthFailure, curr
3513
3521
  platform_name: tenant.platform_name,
3514
3522
  is_advertising: !!((_d = tenantMetadata === null || tenantMetadata === void 0 ? void 0 : tenantMetadata.metadata) === null || _d === void 0 ? void 0 : _d.is_advertising),
3515
3523
  is_enterprise: tenant.is_enterprise,
3524
+ show_paywall: tenant.show_paywall,
3516
3525
  });
3517
3526
  const rbacPermissions = await loadPlatformPermissions(tenant.key);
3518
3527
  onLoadPlatformPermissions === null || onLoadPlatformPermissions === void 0 ? void 0 : onLoadPlatformPermissions(rbacPermissions);
@@ -18982,6 +18991,356 @@ function useProfileImageUpload(options = {}) {
18982
18991
  // This will be deprecated in favor of the new configuration system
18983
18992
  const METADATAS = loadMetadataConfig();
18984
18993
 
18994
+ function __insertCSS(code) {
18995
+ if (typeof document == 'undefined') return
18996
+ let head = document.head || document.getElementsByTagName('head')[0];
18997
+ let style = document.createElement('style');
18998
+ style.type = 'text/css';
18999
+ head.appendChild(style)
19000
+ ;style.styleSheet ? (style.styleSheet.cssText = code) : style.appendChild(document.createTextNode(code));
19001
+ }
19002
+ Array(12).fill(0);
19003
+
19004
+ let toastsCounter = 1;
19005
+ class Observer {
19006
+ constructor(){
19007
+ // We use arrow functions to maintain the correct `this` reference
19008
+ this.subscribe = (subscriber)=>{
19009
+ this.subscribers.push(subscriber);
19010
+ return ()=>{
19011
+ const index = this.subscribers.indexOf(subscriber);
19012
+ this.subscribers.splice(index, 1);
19013
+ };
19014
+ };
19015
+ this.publish = (data)=>{
19016
+ this.subscribers.forEach((subscriber)=>subscriber(data));
19017
+ };
19018
+ this.addToast = (data)=>{
19019
+ this.publish(data);
19020
+ this.toasts = [
19021
+ ...this.toasts,
19022
+ data
19023
+ ];
19024
+ };
19025
+ this.create = (data)=>{
19026
+ var _data_id;
19027
+ const { message, ...rest } = data;
19028
+ const id = typeof (data == null ? void 0 : data.id) === 'number' || ((_data_id = data.id) == null ? void 0 : _data_id.length) > 0 ? data.id : toastsCounter++;
19029
+ const alreadyExists = this.toasts.find((toast)=>{
19030
+ return toast.id === id;
19031
+ });
19032
+ const dismissible = data.dismissible === undefined ? true : data.dismissible;
19033
+ if (this.dismissedToasts.has(id)) {
19034
+ this.dismissedToasts.delete(id);
19035
+ }
19036
+ if (alreadyExists) {
19037
+ this.toasts = this.toasts.map((toast)=>{
19038
+ if (toast.id === id) {
19039
+ this.publish({
19040
+ ...toast,
19041
+ ...data,
19042
+ id,
19043
+ title: message
19044
+ });
19045
+ return {
19046
+ ...toast,
19047
+ ...data,
19048
+ id,
19049
+ dismissible,
19050
+ title: message
19051
+ };
19052
+ }
19053
+ return toast;
19054
+ });
19055
+ } else {
19056
+ this.addToast({
19057
+ title: message,
19058
+ ...rest,
19059
+ dismissible,
19060
+ id
19061
+ });
19062
+ }
19063
+ return id;
19064
+ };
19065
+ this.dismiss = (id)=>{
19066
+ if (id) {
19067
+ this.dismissedToasts.add(id);
19068
+ requestAnimationFrame(()=>this.subscribers.forEach((subscriber)=>subscriber({
19069
+ id,
19070
+ dismiss: true
19071
+ })));
19072
+ } else {
19073
+ this.toasts.forEach((toast)=>{
19074
+ this.subscribers.forEach((subscriber)=>subscriber({
19075
+ id: toast.id,
19076
+ dismiss: true
19077
+ }));
19078
+ });
19079
+ }
19080
+ return id;
19081
+ };
19082
+ this.message = (message, data)=>{
19083
+ return this.create({
19084
+ ...data,
19085
+ message
19086
+ });
19087
+ };
19088
+ this.error = (message, data)=>{
19089
+ return this.create({
19090
+ ...data,
19091
+ message,
19092
+ type: 'error'
19093
+ });
19094
+ };
19095
+ this.success = (message, data)=>{
19096
+ return this.create({
19097
+ ...data,
19098
+ type: 'success',
19099
+ message
19100
+ });
19101
+ };
19102
+ this.info = (message, data)=>{
19103
+ return this.create({
19104
+ ...data,
19105
+ type: 'info',
19106
+ message
19107
+ });
19108
+ };
19109
+ this.warning = (message, data)=>{
19110
+ return this.create({
19111
+ ...data,
19112
+ type: 'warning',
19113
+ message
19114
+ });
19115
+ };
19116
+ this.loading = (message, data)=>{
19117
+ return this.create({
19118
+ ...data,
19119
+ type: 'loading',
19120
+ message
19121
+ });
19122
+ };
19123
+ this.promise = (promise, data)=>{
19124
+ if (!data) {
19125
+ // Nothing to show
19126
+ return;
19127
+ }
19128
+ let id = undefined;
19129
+ if (data.loading !== undefined) {
19130
+ id = this.create({
19131
+ ...data,
19132
+ promise,
19133
+ type: 'loading',
19134
+ message: data.loading,
19135
+ description: typeof data.description !== 'function' ? data.description : undefined
19136
+ });
19137
+ }
19138
+ const p = Promise.resolve(promise instanceof Function ? promise() : promise);
19139
+ let shouldDismiss = id !== undefined;
19140
+ let result;
19141
+ const originalPromise = p.then(async (response)=>{
19142
+ result = [
19143
+ 'resolve',
19144
+ response
19145
+ ];
19146
+ const isReactElementResponse = React.isValidElement(response);
19147
+ if (isReactElementResponse) {
19148
+ shouldDismiss = false;
19149
+ this.create({
19150
+ id,
19151
+ type: 'default',
19152
+ message: response
19153
+ });
19154
+ } else if (isHttpResponse(response) && !response.ok) {
19155
+ shouldDismiss = false;
19156
+ const promiseData = typeof data.error === 'function' ? await data.error(`HTTP error! status: ${response.status}`) : data.error;
19157
+ const description = typeof data.description === 'function' ? await data.description(`HTTP error! status: ${response.status}`) : data.description;
19158
+ const isExtendedResult = typeof promiseData === 'object' && !React.isValidElement(promiseData);
19159
+ const toastSettings = isExtendedResult ? promiseData : {
19160
+ message: promiseData
19161
+ };
19162
+ this.create({
19163
+ id,
19164
+ type: 'error',
19165
+ description,
19166
+ ...toastSettings
19167
+ });
19168
+ } else if (response instanceof Error) {
19169
+ shouldDismiss = false;
19170
+ const promiseData = typeof data.error === 'function' ? await data.error(response) : data.error;
19171
+ const description = typeof data.description === 'function' ? await data.description(response) : data.description;
19172
+ const isExtendedResult = typeof promiseData === 'object' && !React.isValidElement(promiseData);
19173
+ const toastSettings = isExtendedResult ? promiseData : {
19174
+ message: promiseData
19175
+ };
19176
+ this.create({
19177
+ id,
19178
+ type: 'error',
19179
+ description,
19180
+ ...toastSettings
19181
+ });
19182
+ } else if (data.success !== undefined) {
19183
+ shouldDismiss = false;
19184
+ const promiseData = typeof data.success === 'function' ? await data.success(response) : data.success;
19185
+ const description = typeof data.description === 'function' ? await data.description(response) : data.description;
19186
+ const isExtendedResult = typeof promiseData === 'object' && !React.isValidElement(promiseData);
19187
+ const toastSettings = isExtendedResult ? promiseData : {
19188
+ message: promiseData
19189
+ };
19190
+ this.create({
19191
+ id,
19192
+ type: 'success',
19193
+ description,
19194
+ ...toastSettings
19195
+ });
19196
+ }
19197
+ }).catch(async (error)=>{
19198
+ result = [
19199
+ 'reject',
19200
+ error
19201
+ ];
19202
+ if (data.error !== undefined) {
19203
+ shouldDismiss = false;
19204
+ const promiseData = typeof data.error === 'function' ? await data.error(error) : data.error;
19205
+ const description = typeof data.description === 'function' ? await data.description(error) : data.description;
19206
+ const isExtendedResult = typeof promiseData === 'object' && !React.isValidElement(promiseData);
19207
+ const toastSettings = isExtendedResult ? promiseData : {
19208
+ message: promiseData
19209
+ };
19210
+ this.create({
19211
+ id,
19212
+ type: 'error',
19213
+ description,
19214
+ ...toastSettings
19215
+ });
19216
+ }
19217
+ }).finally(()=>{
19218
+ if (shouldDismiss) {
19219
+ // Toast is still in load state (and will be indefinitely — dismiss it)
19220
+ this.dismiss(id);
19221
+ id = undefined;
19222
+ }
19223
+ data.finally == null ? void 0 : data.finally.call(data);
19224
+ });
19225
+ const unwrap = ()=>new Promise((resolve, reject)=>originalPromise.then(()=>result[0] === 'reject' ? reject(result[1]) : resolve(result[1])).catch(reject));
19226
+ if (typeof id !== 'string' && typeof id !== 'number') {
19227
+ // cannot Object.assign on undefined
19228
+ return {
19229
+ unwrap
19230
+ };
19231
+ } else {
19232
+ return Object.assign(id, {
19233
+ unwrap
19234
+ });
19235
+ }
19236
+ };
19237
+ this.custom = (jsx, data)=>{
19238
+ const id = (data == null ? void 0 : data.id) || toastsCounter++;
19239
+ this.create({
19240
+ jsx: jsx(id),
19241
+ id,
19242
+ ...data
19243
+ });
19244
+ return id;
19245
+ };
19246
+ this.getActiveToasts = ()=>{
19247
+ return this.toasts.filter((toast)=>!this.dismissedToasts.has(toast.id));
19248
+ };
19249
+ this.subscribers = [];
19250
+ this.toasts = [];
19251
+ this.dismissedToasts = new Set();
19252
+ }
19253
+ }
19254
+ const ToastState = new Observer();
19255
+ // bind this to the toast function
19256
+ const toastFunction = (message, data)=>{
19257
+ const id = (data == null ? void 0 : data.id) || toastsCounter++;
19258
+ ToastState.addToast({
19259
+ title: message,
19260
+ ...data,
19261
+ id
19262
+ });
19263
+ return id;
19264
+ };
19265
+ const isHttpResponse = (data)=>{
19266
+ return data && typeof data === 'object' && 'ok' in data && typeof data.ok === 'boolean' && 'status' in data && typeof data.status === 'number';
19267
+ };
19268
+ const basicToast = toastFunction;
19269
+ const getHistory = ()=>ToastState.toasts;
19270
+ const getToasts = ()=>ToastState.getActiveToasts();
19271
+ // We use `Object.assign` to maintain the correct types as we would lose them otherwise
19272
+ const toast = Object.assign(basicToast, {
19273
+ success: ToastState.success,
19274
+ info: ToastState.info,
19275
+ warning: ToastState.warning,
19276
+ error: ToastState.error,
19277
+ custom: ToastState.custom,
19278
+ message: ToastState.message,
19279
+ promise: ToastState.promise,
19280
+ dismiss: ToastState.dismiss,
19281
+ loading: ToastState.loading
19282
+ }, {
19283
+ getHistory,
19284
+ getToasts
19285
+ });
19286
+
19287
+ __insertCSS("[data-sonner-toaster][dir=ltr],html[dir=ltr]{--toast-icon-margin-start:-3px;--toast-icon-margin-end:4px;--toast-svg-margin-start:-1px;--toast-svg-margin-end:0px;--toast-button-margin-start:auto;--toast-button-margin-end:0;--toast-close-button-start:0;--toast-close-button-end:unset;--toast-close-button-transform:translate(-35%, -35%)}[data-sonner-toaster][dir=rtl],html[dir=rtl]{--toast-icon-margin-start:4px;--toast-icon-margin-end:-3px;--toast-svg-margin-start:0px;--toast-svg-margin-end:-1px;--toast-button-margin-start:0;--toast-button-margin-end:auto;--toast-close-button-start:unset;--toast-close-button-end:0;--toast-close-button-transform:translate(35%, -35%)}[data-sonner-toaster]{position:fixed;width:var(--width);font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;--gray1:hsl(0, 0%, 99%);--gray2:hsl(0, 0%, 97.3%);--gray3:hsl(0, 0%, 95.1%);--gray4:hsl(0, 0%, 93%);--gray5:hsl(0, 0%, 90.9%);--gray6:hsl(0, 0%, 88.7%);--gray7:hsl(0, 0%, 85.8%);--gray8:hsl(0, 0%, 78%);--gray9:hsl(0, 0%, 56.1%);--gray10:hsl(0, 0%, 52.3%);--gray11:hsl(0, 0%, 43.5%);--gray12:hsl(0, 0%, 9%);--border-radius:8px;box-sizing:border-box;padding:0;margin:0;list-style:none;outline:0;z-index:999999999;transition:transform .4s ease}@media (hover:none) and (pointer:coarse){[data-sonner-toaster][data-lifted=true]{transform:none}}[data-sonner-toaster][data-x-position=right]{right:var(--offset-right)}[data-sonner-toaster][data-x-position=left]{left:var(--offset-left)}[data-sonner-toaster][data-x-position=center]{left:50%;transform:translateX(-50%)}[data-sonner-toaster][data-y-position=top]{top:var(--offset-top)}[data-sonner-toaster][data-y-position=bottom]{bottom:var(--offset-bottom)}[data-sonner-toast]{--y:translateY(100%);--lift-amount:calc(var(--lift) * var(--gap));z-index:var(--z-index);position:absolute;opacity:0;transform:var(--y);touch-action:none;transition:transform .4s,opacity .4s,height .4s,box-shadow .2s;box-sizing:border-box;outline:0;overflow-wrap:anywhere}[data-sonner-toast][data-styled=true]{padding:16px;background:var(--normal-bg);border:1px solid var(--normal-border);color:var(--normal-text);border-radius:var(--border-radius);box-shadow:0 4px 12px rgba(0,0,0,.1);width:var(--width);font-size:13px;display:flex;align-items:center;gap:6px}[data-sonner-toast]:focus-visible{box-shadow:0 4px 12px rgba(0,0,0,.1),0 0 0 2px rgba(0,0,0,.2)}[data-sonner-toast][data-y-position=top]{top:0;--y:translateY(-100%);--lift:1;--lift-amount:calc(1 * var(--gap))}[data-sonner-toast][data-y-position=bottom]{bottom:0;--y:translateY(100%);--lift:-1;--lift-amount:calc(var(--lift) * var(--gap))}[data-sonner-toast][data-styled=true] [data-description]{font-weight:400;line-height:1.4;color:#3f3f3f}[data-rich-colors=true][data-sonner-toast][data-styled=true] [data-description]{color:inherit}[data-sonner-toaster][data-sonner-theme=dark] [data-description]{color:#e8e8e8}[data-sonner-toast][data-styled=true] [data-title]{font-weight:500;line-height:1.5;color:inherit}[data-sonner-toast][data-styled=true] [data-icon]{display:flex;height:16px;width:16px;position:relative;justify-content:flex-start;align-items:center;flex-shrink:0;margin-left:var(--toast-icon-margin-start);margin-right:var(--toast-icon-margin-end)}[data-sonner-toast][data-promise=true] [data-icon]>svg{opacity:0;transform:scale(.8);transform-origin:center;animation:sonner-fade-in .3s ease forwards}[data-sonner-toast][data-styled=true] [data-icon]>*{flex-shrink:0}[data-sonner-toast][data-styled=true] [data-icon] svg{margin-left:var(--toast-svg-margin-start);margin-right:var(--toast-svg-margin-end)}[data-sonner-toast][data-styled=true] [data-content]{display:flex;flex-direction:column;gap:2px}[data-sonner-toast][data-styled=true] [data-button]{border-radius:4px;padding-left:8px;padding-right:8px;height:24px;font-size:12px;color:var(--normal-bg);background:var(--normal-text);margin-left:var(--toast-button-margin-start);margin-right:var(--toast-button-margin-end);border:none;font-weight:500;cursor:pointer;outline:0;display:flex;align-items:center;flex-shrink:0;transition:opacity .4s,box-shadow .2s}[data-sonner-toast][data-styled=true] [data-button]:focus-visible{box-shadow:0 0 0 2px rgba(0,0,0,.4)}[data-sonner-toast][data-styled=true] [data-button]:first-of-type{margin-left:var(--toast-button-margin-start);margin-right:var(--toast-button-margin-end)}[data-sonner-toast][data-styled=true] [data-cancel]{color:var(--normal-text);background:rgba(0,0,0,.08)}[data-sonner-toaster][data-sonner-theme=dark] [data-sonner-toast][data-styled=true] [data-cancel]{background:rgba(255,255,255,.3)}[data-sonner-toast][data-styled=true] [data-close-button]{position:absolute;left:var(--toast-close-button-start);right:var(--toast-close-button-end);top:0;height:20px;width:20px;display:flex;justify-content:center;align-items:center;padding:0;color:var(--gray12);background:var(--normal-bg);border:1px solid var(--gray4);transform:var(--toast-close-button-transform);border-radius:50%;cursor:pointer;z-index:1;transition:opacity .1s,background .2s,border-color .2s}[data-sonner-toast][data-styled=true] [data-close-button]:focus-visible{box-shadow:0 4px 12px rgba(0,0,0,.1),0 0 0 2px rgba(0,0,0,.2)}[data-sonner-toast][data-styled=true] [data-disabled=true]{cursor:not-allowed}[data-sonner-toast][data-styled=true]:hover [data-close-button]:hover{background:var(--gray2);border-color:var(--gray5)}[data-sonner-toast][data-swiping=true]::before{content:'';position:absolute;left:-100%;right:-100%;height:100%;z-index:-1}[data-sonner-toast][data-y-position=top][data-swiping=true]::before{bottom:50%;transform:scaleY(3) translateY(50%)}[data-sonner-toast][data-y-position=bottom][data-swiping=true]::before{top:50%;transform:scaleY(3) translateY(-50%)}[data-sonner-toast][data-swiping=false][data-removed=true]::before{content:'';position:absolute;inset:0;transform:scaleY(2)}[data-sonner-toast][data-expanded=true]::after{content:'';position:absolute;left:0;height:calc(var(--gap) + 1px);bottom:100%;width:100%}[data-sonner-toast][data-mounted=true]{--y:translateY(0);opacity:1}[data-sonner-toast][data-expanded=false][data-front=false]{--scale:var(--toasts-before) * 0.05 + 1;--y:translateY(calc(var(--lift-amount) * var(--toasts-before))) scale(calc(-1 * var(--scale)));height:var(--front-toast-height)}[data-sonner-toast]>*{transition:opacity .4s}[data-sonner-toast][data-x-position=right]{right:0}[data-sonner-toast][data-x-position=left]{left:0}[data-sonner-toast][data-expanded=false][data-front=false][data-styled=true]>*{opacity:0}[data-sonner-toast][data-visible=false]{opacity:0;pointer-events:none}[data-sonner-toast][data-mounted=true][data-expanded=true]{--y:translateY(calc(var(--lift) * var(--offset)));height:var(--initial-height)}[data-sonner-toast][data-removed=true][data-front=true][data-swipe-out=false]{--y:translateY(calc(var(--lift) * -100%));opacity:0}[data-sonner-toast][data-removed=true][data-front=false][data-swipe-out=false][data-expanded=true]{--y:translateY(calc(var(--lift) * var(--offset) + var(--lift) * -100%));opacity:0}[data-sonner-toast][data-removed=true][data-front=false][data-swipe-out=false][data-expanded=false]{--y:translateY(40%);opacity:0;transition:transform .5s,opacity .2s}[data-sonner-toast][data-removed=true][data-front=false]::before{height:calc(var(--initial-height) + 20%)}[data-sonner-toast][data-swiping=true]{transform:var(--y) translateY(var(--swipe-amount-y,0)) translateX(var(--swipe-amount-x,0));transition:none}[data-sonner-toast][data-swiped=true]{user-select:none}[data-sonner-toast][data-swipe-out=true][data-y-position=bottom],[data-sonner-toast][data-swipe-out=true][data-y-position=top]{animation-duration:.2s;animation-timing-function:ease-out;animation-fill-mode:forwards}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=left]{animation-name:swipe-out-left}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=right]{animation-name:swipe-out-right}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=up]{animation-name:swipe-out-up}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=down]{animation-name:swipe-out-down}@keyframes swipe-out-left{from{transform:var(--y) translateX(var(--swipe-amount-x));opacity:1}to{transform:var(--y) translateX(calc(var(--swipe-amount-x) - 100%));opacity:0}}@keyframes swipe-out-right{from{transform:var(--y) translateX(var(--swipe-amount-x));opacity:1}to{transform:var(--y) translateX(calc(var(--swipe-amount-x) + 100%));opacity:0}}@keyframes swipe-out-up{from{transform:var(--y) translateY(var(--swipe-amount-y));opacity:1}to{transform:var(--y) translateY(calc(var(--swipe-amount-y) - 100%));opacity:0}}@keyframes swipe-out-down{from{transform:var(--y) translateY(var(--swipe-amount-y));opacity:1}to{transform:var(--y) translateY(calc(var(--swipe-amount-y) + 100%));opacity:0}}@media (max-width:600px){[data-sonner-toaster]{position:fixed;right:var(--mobile-offset-right);left:var(--mobile-offset-left);width:100%}[data-sonner-toaster][dir=rtl]{left:calc(var(--mobile-offset-left) * -1)}[data-sonner-toaster] [data-sonner-toast]{left:0;right:0;width:calc(100% - var(--mobile-offset-left) * 2)}[data-sonner-toaster][data-x-position=left]{left:var(--mobile-offset-left)}[data-sonner-toaster][data-y-position=bottom]{bottom:var(--mobile-offset-bottom)}[data-sonner-toaster][data-y-position=top]{top:var(--mobile-offset-top)}[data-sonner-toaster][data-x-position=center]{left:var(--mobile-offset-left);right:var(--mobile-offset-right);transform:none}}[data-sonner-toaster][data-sonner-theme=light]{--normal-bg:#fff;--normal-border:var(--gray4);--normal-text:var(--gray12);--success-bg:hsl(143, 85%, 96%);--success-border:hsl(145, 92%, 87%);--success-text:hsl(140, 100%, 27%);--info-bg:hsl(208, 100%, 97%);--info-border:hsl(221, 91%, 93%);--info-text:hsl(210, 92%, 45%);--warning-bg:hsl(49, 100%, 97%);--warning-border:hsl(49, 91%, 84%);--warning-text:hsl(31, 92%, 45%);--error-bg:hsl(359, 100%, 97%);--error-border:hsl(359, 100%, 94%);--error-text:hsl(360, 100%, 45%)}[data-sonner-toaster][data-sonner-theme=light] [data-sonner-toast][data-invert=true]{--normal-bg:#000;--normal-border:hsl(0, 0%, 20%);--normal-text:var(--gray1)}[data-sonner-toaster][data-sonner-theme=dark] [data-sonner-toast][data-invert=true]{--normal-bg:#fff;--normal-border:var(--gray3);--normal-text:var(--gray12)}[data-sonner-toaster][data-sonner-theme=dark]{--normal-bg:#000;--normal-bg-hover:hsl(0, 0%, 12%);--normal-border:hsl(0, 0%, 20%);--normal-border-hover:hsl(0, 0%, 25%);--normal-text:var(--gray1);--success-bg:hsl(150, 100%, 6%);--success-border:hsl(147, 100%, 12%);--success-text:hsl(150, 86%, 65%);--info-bg:hsl(215, 100%, 6%);--info-border:hsl(223, 43%, 17%);--info-text:hsl(216, 87%, 65%);--warning-bg:hsl(64, 100%, 6%);--warning-border:hsl(60, 100%, 9%);--warning-text:hsl(46, 87%, 65%);--error-bg:hsl(358, 76%, 10%);--error-border:hsl(357, 89%, 16%);--error-text:hsl(358, 100%, 81%)}[data-sonner-toaster][data-sonner-theme=dark] [data-sonner-toast] [data-close-button]{background:var(--normal-bg);border-color:var(--normal-border);color:var(--normal-text)}[data-sonner-toaster][data-sonner-theme=dark] [data-sonner-toast] [data-close-button]:hover{background:var(--normal-bg-hover);border-color:var(--normal-border-hover)}[data-rich-colors=true][data-sonner-toast][data-type=success]{background:var(--success-bg);border-color:var(--success-border);color:var(--success-text)}[data-rich-colors=true][data-sonner-toast][data-type=success] [data-close-button]{background:var(--success-bg);border-color:var(--success-border);color:var(--success-text)}[data-rich-colors=true][data-sonner-toast][data-type=info]{background:var(--info-bg);border-color:var(--info-border);color:var(--info-text)}[data-rich-colors=true][data-sonner-toast][data-type=info] [data-close-button]{background:var(--info-bg);border-color:var(--info-border);color:var(--info-text)}[data-rich-colors=true][data-sonner-toast][data-type=warning]{background:var(--warning-bg);border-color:var(--warning-border);color:var(--warning-text)}[data-rich-colors=true][data-sonner-toast][data-type=warning] [data-close-button]{background:var(--warning-bg);border-color:var(--warning-border);color:var(--warning-text)}[data-rich-colors=true][data-sonner-toast][data-type=error]{background:var(--error-bg);border-color:var(--error-border);color:var(--error-text)}[data-rich-colors=true][data-sonner-toast][data-type=error] [data-close-button]{background:var(--error-bg);border-color:var(--error-border);color:var(--error-text)}.sonner-loading-wrapper{--size:16px;height:var(--size);width:var(--size);position:absolute;inset:0;z-index:10}.sonner-loading-wrapper[data-visible=false]{transform-origin:center;animation:sonner-fade-out .2s ease forwards}.sonner-spinner{position:relative;top:50%;left:50%;height:var(--size);width:var(--size)}.sonner-loading-bar{animation:sonner-spin 1.2s linear infinite;background:var(--gray11);border-radius:6px;height:8%;left:-10%;position:absolute;top:-3.9%;width:24%}.sonner-loading-bar:first-child{animation-delay:-1.2s;transform:rotate(.0001deg) translate(146%)}.sonner-loading-bar:nth-child(2){animation-delay:-1.1s;transform:rotate(30deg) translate(146%)}.sonner-loading-bar:nth-child(3){animation-delay:-1s;transform:rotate(60deg) translate(146%)}.sonner-loading-bar:nth-child(4){animation-delay:-.9s;transform:rotate(90deg) translate(146%)}.sonner-loading-bar:nth-child(5){animation-delay:-.8s;transform:rotate(120deg) translate(146%)}.sonner-loading-bar:nth-child(6){animation-delay:-.7s;transform:rotate(150deg) translate(146%)}.sonner-loading-bar:nth-child(7){animation-delay:-.6s;transform:rotate(180deg) translate(146%)}.sonner-loading-bar:nth-child(8){animation-delay:-.5s;transform:rotate(210deg) translate(146%)}.sonner-loading-bar:nth-child(9){animation-delay:-.4s;transform:rotate(240deg) translate(146%)}.sonner-loading-bar:nth-child(10){animation-delay:-.3s;transform:rotate(270deg) translate(146%)}.sonner-loading-bar:nth-child(11){animation-delay:-.2s;transform:rotate(300deg) translate(146%)}.sonner-loading-bar:nth-child(12){animation-delay:-.1s;transform:rotate(330deg) translate(146%)}@keyframes sonner-fade-in{0%{opacity:0;transform:scale(.8)}100%{opacity:1;transform:scale(1)}}@keyframes sonner-fade-out{0%{opacity:1;transform:scale(1)}100%{opacity:0;transform:scale(.8)}}@keyframes sonner-spin{0%{opacity:1}100%{opacity:.15}}@media (prefers-reduced-motion){.sonner-loading-bar,[data-sonner-toast],[data-sonner-toast]>*{transition:none!important;animation:none!important}}.sonner-loader{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);transform-origin:center;transition:opacity .2s,transform .2s}.sonner-loader[data-visible=false]{opacity:0;transform:scale(.8) translate(-50%,-50%)}");
19288
+
19289
+ function buildCheckoutUrl(baseUrl, email, clientReferenceId) {
19290
+ const separator = baseUrl.includes("?") ? "&" : "?";
19291
+ return `${baseUrl}${separator}locked_prefilled_email=${encodeURIComponent(email)}&client_reference_id=${encodeURIComponent(clientReferenceId)}`;
19292
+ }
19293
+ const useStripeUpgrade = ({ redirectUrl, sourcePlatformKey, mainPlatformKey, currentUserEmail, }) => {
19294
+ const [triggerGetSession] = dataLayer.useLazyGetStripePricingPageSessionQuery();
19295
+ const [isLoading, setIsLoading] = React.useState(false);
19296
+ const [freeUrl, setFreeUrl] = React.useState(null);
19297
+ const [premiumUrl, setPremiumUrl] = React.useState(null);
19298
+ const handleUpgrade = async (redirectPlan) => {
19299
+ setIsLoading(true);
19300
+ try {
19301
+ const result = await triggerGetSession({
19302
+ platform_key: mainPlatformKey,
19303
+ params: {
19304
+ redirect_url: redirectUrl,
19305
+ source_platform_key: sourcePlatformKey,
19306
+ },
19307
+ }).unwrap();
19308
+ const { payment_link_url, client_reference_id } = result;
19309
+ if (!payment_link_url || !isJSON(payment_link_url)) {
19310
+ return;
19311
+ }
19312
+ const links = JSON.parse(payment_link_url);
19313
+ const referenceId = client_reference_id !== null && client_reference_id !== void 0 ? client_reference_id : "";
19314
+ const resolvedFreeUrl = links.free
19315
+ ? buildCheckoutUrl(links.free, currentUserEmail, referenceId)
19316
+ : null;
19317
+ const resolvedPremiumUrl = links.premium
19318
+ ? buildCheckoutUrl(links.premium, currentUserEmail, referenceId)
19319
+ : null;
19320
+ setFreeUrl(resolvedFreeUrl);
19321
+ setPremiumUrl(resolvedPremiumUrl);
19322
+ if (!redirectPlan)
19323
+ return;
19324
+ const target = redirectPlan === "free" ? resolvedFreeUrl : resolvedPremiumUrl;
19325
+ if (target) {
19326
+ window.location.href = target;
19327
+ }
19328
+ }
19329
+ catch (_a) {
19330
+ toast.error("Failed to load upgrade options. Please try again.");
19331
+ }
19332
+ finally {
19333
+ setIsLoading(false);
19334
+ }
19335
+ };
19336
+ return {
19337
+ isLoading,
19338
+ freeUrl,
19339
+ premiumUrl,
19340
+ handleUpgrade,
19341
+ };
19342
+ };
19343
+
18985
19344
  var util;
18986
19345
  (function (util) {
18987
19346
  util.assertEqual = (val) => val;
@@ -23749,6 +24108,7 @@ exports.useExternalPricingPlan = useExternalPricingPlan;
23749
24108
  exports.useMentorSettings = useMentorSettings;
23750
24109
  exports.useMentorTools = useMentorTools;
23751
24110
  exports.useProfileImageUpload = useProfileImageUpload;
24111
+ exports.useStripeUpgrade = useStripeUpgrade;
23752
24112
  exports.useSubscriptionHandler = useSubscriptionHandler;
23753
24113
  exports.useSubscriptionHandlerV2 = useSubscriptionHandlerV2;
23754
24114
  exports.useTenantContext = useTenantContext;