@sawport/react-sdk 0.9.9-alpha.5 → 0.9.9-alpha.6

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
@@ -14671,7 +14671,7 @@ var t$4 = new EventEmitter$1(), o$3 = function(n2, e2) {
14671
14671
  }, i$3 = function() {
14672
14672
  return reactExports.useRef(t$4).current;
14673
14673
  };
14674
- var define_import_meta_env_default$2 = { BASE_URL: "/", MODE: "production", DEV: false, PROD: true, SSR: false };
14674
+ var define_import_meta_env_default$2 = { VITE_BASE_URL: "http://localhost:5000", VITE_API_URL: "http://localhost:5000/api/v1/", VITE_PROJECT_ID: "dc956202-5374-4256-985e-a492fcd26992", BASE_URL: "/", MODE: "production", DEV: false, PROD: true, SSR: false };
14675
14675
  const createStoreImpl = (createState) => {
14676
14676
  let state;
14677
14677
  const listeners2 = /* @__PURE__ */ new Set();
@@ -14818,7 +14818,7 @@ withSelector_production_min.useSyncExternalStoreWithSelector = function(a2, b2,
14818
14818
  }
14819
14819
  var withSelectorExports = withSelector.exports;
14820
14820
  const useSyncExternalStoreExports = /* @__PURE__ */ getDefaultExportFromCjs(withSelectorExports);
14821
- var define_import_meta_env_default$1 = { BASE_URL: "/", MODE: "production", DEV: false, PROD: true, SSR: false };
14821
+ var define_import_meta_env_default$1 = { VITE_BASE_URL: "http://localhost:5000", VITE_API_URL: "http://localhost:5000/api/v1/", VITE_PROJECT_ID: "dc956202-5374-4256-985e-a492fcd26992", BASE_URL: "/", MODE: "production", DEV: false, PROD: true, SSR: false };
14822
14822
  const { useDebugValue } = React$2;
14823
14823
  const { useSyncExternalStoreWithSelector } = useSyncExternalStoreExports;
14824
14824
  let didWarnAboutEqualityFn = false;
@@ -15484,7 +15484,7 @@ const immerImpl = (initializer) => (set2, get2, store) => {
15484
15484
  return initializer(store.setState, get2, store);
15485
15485
  };
15486
15486
  const immer = immerImpl;
15487
- var define_import_meta_env_default = { BASE_URL: "/", MODE: "production", DEV: false, PROD: true, SSR: false };
15487
+ var define_import_meta_env_default = { VITE_BASE_URL: "http://localhost:5000", VITE_API_URL: "http://localhost:5000/api/v1/", VITE_PROJECT_ID: "dc956202-5374-4256-985e-a492fcd26992", BASE_URL: "/", MODE: "production", DEV: false, PROD: true, SSR: false };
15488
15488
  const trackedConnections = /* @__PURE__ */ new Map();
15489
15489
  const getTrackedConnectionState = (name) => {
15490
15490
  const api2 = trackedConnections.get(name);
@@ -25687,6 +25687,9 @@ const exts = {
25687
25687
  docm: "document",
25688
25688
  odt: "document",
25689
25689
  pdf: "document",
25690
+ mp3: "audio",
25691
+ wav: "audio",
25692
+ m4a: "audio",
25690
25693
  "vnd.openxmlformats-officedocument.wordprocessingml.document": "document"
25691
25694
  };
25692
25695
  const isFileType = (ext) => exts[ext];
@@ -102870,6 +102873,93 @@ const useChatStore = create(
102870
102873
  { name: "@chat" }
102871
102874
  )
102872
102875
  );
102876
+ const VoiceRecording = reactExports.memo(({
102877
+ clearRecording,
102878
+ isRecording,
102879
+ recordingTime,
102880
+ isPaused,
102881
+ togglePauseResume,
102882
+ stopRecording,
102883
+ startRecording,
102884
+ url: url3
102885
+ }) => {
102886
+ return /* @__PURE__ */ jsx("div", {
102887
+ className: "flex justify-between items-center my-3 pr-4",
102888
+ children: url3 ? /* @__PURE__ */ jsx(Fragment, {
102889
+ children: /* @__PURE__ */ jsxs("div", {
102890
+ className: "flex items-center text-red-500",
102891
+ children: [/* @__PURE__ */ jsx("audio", {
102892
+ controls: true,
102893
+ controlsList: "nodownload noplaybackrate novolume",
102894
+ src: url3
102895
+ }), /* @__PURE__ */ jsx("div", {
102896
+ className: "ml-2",
102897
+ title: "Delete recording",
102898
+ children: /* @__PURE__ */ jsx(SvgTrash, {
102899
+ onClick: clearRecording,
102900
+ className: "pointer",
102901
+ stroke: "red",
102902
+ width: 20,
102903
+ height: 20
102904
+ })
102905
+ })]
102906
+ })
102907
+ }) : isRecording ? /* @__PURE__ */ jsxs(Fragment, {
102908
+ children: [/* @__PURE__ */ jsxs(Col$1, {
102909
+ className: "flex text-red-500",
102910
+ children: [/* @__PURE__ */ jsx(SvgMic, {
102911
+ width: 20,
102912
+ height: 20,
102913
+ className: "mr-2"
102914
+ }), /* @__PURE__ */ jsx(Interval, {
102915
+ Render: () => /* @__PURE__ */ jsx(Fragment, {
102916
+ children: hooks.utc((30 - recordingTime) * 1e3).format("HH:mm:ss")
102917
+ })
102918
+ })]
102919
+ }), /* @__PURE__ */ jsx(Col$1, {
102920
+ className: "text-red-500 animate-blink",
102921
+ children: "Recording"
102922
+ }), /* @__PURE__ */ jsxs(Row$1, {
102923
+ className: "flex items-center",
102924
+ children: [/* @__PURE__ */ jsx(Col$1, {
102925
+ title: isPaused ? "Play" : "Pause",
102926
+ onClick: togglePauseResume,
102927
+ className: "pointer",
102928
+ children: isPaused ? /* @__PURE__ */ jsx(SvgPlay, {
102929
+ width: 20,
102930
+ height: 20
102931
+ }) : /* @__PURE__ */ jsx(SvgPause, {
102932
+ width: 20,
102933
+ height: 20
102934
+ })
102935
+ }), /* @__PURE__ */ jsx(Col$1, {
102936
+ title: "Stop recording",
102937
+ onClick: stopRecording,
102938
+ className: "pointer",
102939
+ children: /* @__PURE__ */ jsx(SvgStop, {
102940
+ width: 20,
102941
+ height: 20
102942
+ })
102943
+ })]
102944
+ })]
102945
+ }) : /* @__PURE__ */ jsxs("div", {
102946
+ title: "Click mic to start recording",
102947
+ onClick: startRecording,
102948
+ className: "cursor-pointer flex items-center",
102949
+ children: [/* @__PURE__ */ jsx("span", {
102950
+ className: "mr-2",
102951
+ style: {
102952
+ fontSize: 14
102953
+ },
102954
+ children: "Click mic to start recording"
102955
+ }), /* @__PURE__ */ jsx(SvgMic, {
102956
+ stroke: "red",
102957
+ width: 20,
102958
+ height: 20
102959
+ })]
102960
+ })
102961
+ });
102962
+ });
102873
102963
  const Offline = reactExports.memo(({
102874
102964
  company_id,
102875
102965
  website_name,
@@ -103224,81 +103314,15 @@ const Offline = reactExports.memo(({
103224
103314
  values,
103225
103315
  touched,
103226
103316
  errors
103227
- }), values.reason === "Leave a voice note" && /* @__PURE__ */ jsx("div", {
103228
- className: "flex justify-between items-center mt-3 pr-4",
103229
- children: url3 ? /* @__PURE__ */ jsx(Fragment, {
103230
- children: /* @__PURE__ */ jsxs("div", {
103231
- className: "flex items-center text-red-500",
103232
- children: [/* @__PURE__ */ jsx("audio", {
103233
- controls: true,
103234
- controlsList: "nodownload noplaybackrate novolume",
103235
- src: url3
103236
- }), /* @__PURE__ */ jsx("div", {
103237
- className: "ml-2",
103238
- title: "Delete recording",
103239
- children: /* @__PURE__ */ jsx(SvgTrash, {
103240
- onClick: clearRecording,
103241
- className: "pointer",
103242
- stroke: "red",
103243
- width: 20,
103244
- height: 20
103245
- })
103246
- })]
103247
- })
103248
- }) : isRecording ? /* @__PURE__ */ jsxs(Fragment, {
103249
- children: [/* @__PURE__ */ jsxs(Col$1, {
103250
- className: "flex text-red-500",
103251
- children: [/* @__PURE__ */ jsx(SvgMic, {
103252
- width: 20,
103253
- height: 20,
103254
- className: "mr-2"
103255
- }), /* @__PURE__ */ jsx(Interval, {
103256
- Render: () => /* @__PURE__ */ jsx(Fragment, {
103257
- children: hooks.utc((30 - recordingTime) * 1e3).format("HH:mm:ss")
103258
- })
103259
- })]
103260
- }), /* @__PURE__ */ jsx(Col$1, {
103261
- className: "text-red-500 animate-blink",
103262
- children: "Recording"
103263
- }), /* @__PURE__ */ jsxs(Row$1, {
103264
- className: "flex items-center",
103265
- children: [/* @__PURE__ */ jsx(Col$1, {
103266
- title: isPaused ? "Play" : "Pause",
103267
- onClick: togglePauseResume,
103268
- className: "pointer",
103269
- children: isPaused ? /* @__PURE__ */ jsx(SvgPlay, {
103270
- width: 20,
103271
- height: 20
103272
- }) : /* @__PURE__ */ jsx(SvgPause, {
103273
- width: 20,
103274
- height: 20
103275
- })
103276
- }), /* @__PURE__ */ jsx(Col$1, {
103277
- title: "Stop recording",
103278
- onClick: stopRecording,
103279
- className: "pointer",
103280
- children: /* @__PURE__ */ jsx(SvgStop, {
103281
- width: 20,
103282
- height: 20
103283
- })
103284
- })]
103285
- })]
103286
- }) : /* @__PURE__ */ jsxs("div", {
103287
- title: "Click mic to start recording",
103288
- onClick: startRecording,
103289
- className: "cursor-pointer flex items-center",
103290
- children: [/* @__PURE__ */ jsx("span", {
103291
- className: "mr-2",
103292
- style: {
103293
- fontSize: 14
103294
- },
103295
- children: "Click mic to start recording"
103296
- }), /* @__PURE__ */ jsx(SvgMic, {
103297
- stroke: "red",
103298
- width: 20,
103299
- height: 20
103300
- })]
103301
- })
103317
+ }), values.reason === "Leave a voice note" && /* @__PURE__ */ jsx(VoiceRecording, {
103318
+ clearRecording,
103319
+ isRecording,
103320
+ recordingTime,
103321
+ isPaused,
103322
+ togglePauseResume,
103323
+ stopRecording,
103324
+ startRecording,
103325
+ url: url3
103302
103326
  }), /* @__PURE__ */ jsxs("div", {
103303
103327
  className: "mt-3 mb-0",
103304
103328
  children: [/* @__PURE__ */ jsxs(Button$1, {
@@ -103542,7 +103566,7 @@ function WidgetInitForm({
103542
103566
  }) {
103543
103567
  var _a, _b;
103544
103568
  const user2 = (customer == null ? void 0 : customer.email) ? customer : companyUser;
103545
- useChatStore();
103569
+ const callRequestOptions = reactExports.useMemo(() => [...(options == null ? void 0 : options.enableVoicenote) ? ["Leave a voice note"] : [], ...options.callRequestOptions || []], [options == null ? void 0 : options.enableVoicenote, options.callRequestOptions]);
103546
103570
  const [{
103547
103571
  ipAddress,
103548
103572
  country,
@@ -103564,6 +103588,17 @@ function WidgetInitForm({
103564
103588
  continent: void 0,
103565
103589
  timezone: void 0
103566
103590
  });
103591
+ const {
103592
+ recordingTime,
103593
+ startRecording,
103594
+ stopRecording,
103595
+ isPaused,
103596
+ togglePauseResume,
103597
+ isRecording,
103598
+ recordingBlob,
103599
+ clearRecording,
103600
+ url: url3
103601
+ } = useAudioRecorder();
103567
103602
  const validSchema = reactExports.useMemo(() => {
103568
103603
  const shape = {
103569
103604
  name: create$4().min(3).required(),
@@ -103655,28 +103690,35 @@ function WidgetInitForm({
103655
103690
  return;
103656
103691
  }
103657
103692
  }
103658
- return initMessage({
103659
- name,
103660
- email: email2,
103661
- reason: reason2,
103662
- credentials: mobile ? {
103663
- mobile,
103664
- ...emptyFields2,
103665
- calling_code: emptyFields2.calling_code || calling_code
103666
- } : {
103667
- ...emptyFields2
103668
- },
103669
- company: company_id,
103670
- ip_address: ipAddress,
103671
- country,
103672
- latitude,
103673
- longitude,
103674
- location: location2,
103675
- source_url,
103676
- continent,
103677
- timezone: timezone2,
103678
- access_platform: "web"
103679
- });
103693
+ const formData = new FormData();
103694
+ formData.append("name", name);
103695
+ formData.append("email", email2);
103696
+ formData.append("reason", reason2);
103697
+ formData.append("company", company_id);
103698
+ ipAddress && formData.append("ip_address", ipAddress);
103699
+ source_url && formData.append("source_url", source_url);
103700
+ location2 && formData.append("location", location2);
103701
+ country && formData.append("country", country);
103702
+ longitude && formData.append("longitude", longitude);
103703
+ latitude && formData.append("latitude", latitude);
103704
+ continent && formData.append("continent", continent);
103705
+ formData.append("timezone", timezone2);
103706
+ formData.append("calling_code", calling_code);
103707
+ formData.append("access_platform", "web");
103708
+ if (mobile) {
103709
+ formData.append("credentials[mobile]", mobile);
103710
+ formData.append("credentials[calling_code]", emptyFields2.calling_code || calling_code);
103711
+ } else {
103712
+ Object.keys(emptyFields2).map((key) => {
103713
+ formData.append(`credentials[${key}]`, emptyFields2[key]);
103714
+ });
103715
+ }
103716
+ if (recordingBlob) {
103717
+ const attachment = new File([recordingBlob], "attachment.webm");
103718
+ formData.append("attachment", attachment);
103719
+ clearRecording();
103720
+ }
103721
+ return initMessage(formData);
103680
103722
  }, {
103681
103723
  onError: (err) => {
103682
103724
  console.log("error", err);
@@ -103813,13 +103855,22 @@ function WidgetInitForm({
103813
103855
  label: "Call Reason",
103814
103856
  name: "reason",
103815
103857
  type: "select",
103816
- options: (options == null ? void 0 : options.callRequestOptions) || [],
103858
+ options: callRequestOptions,
103817
103859
  placeholder: "Why did you want to call?",
103818
103860
  onChange: formik.handleChange,
103819
103861
  onBlur: formik.handleBlur,
103820
103862
  values: formik.values,
103821
103863
  touched: formik.touched,
103822
103864
  errors: formik.errors
103865
+ }), formik.values.reason === "Leave a voice note" && /* @__PURE__ */ jsx(VoiceRecording, {
103866
+ clearRecording,
103867
+ isRecording,
103868
+ recordingTime,
103869
+ isPaused,
103870
+ togglePauseResume,
103871
+ stopRecording,
103872
+ startRecording,
103873
+ url: url3
103823
103874
  }), /* @__PURE__ */ jsxs("div", {
103824
103875
  className: "mt-auto",
103825
103876
  style: {
@@ -103829,7 +103880,7 @@ function WidgetInitForm({
103829
103880
  children: [/* @__PURE__ */ jsxs(Button$1, {
103830
103881
  type: "primary",
103831
103882
  htmlType: "submit",
103832
- disabled: isLoading,
103883
+ disabled: isLoading || formik.values.reason === "Leave a voice note" && !recordingTime,
103833
103884
  className: "flex justify-center border-0 items-center my-1 py-1 px-4 flex-1 w-full",
103834
103885
  children: [isLoading ? /* @__PURE__ */ jsx(SpinFC$1, {
103835
103886
  className: "mr-2",
@@ -103915,7 +103966,7 @@ function Feedback({
103915
103966
  try {
103916
103967
  await createFeedback({
103917
103968
  agent: agent == null ? void 0 : agent.id,
103918
- rating,
103969
+ rating: rating * 20,
103919
103970
  conversation,
103920
103971
  comment: comment2,
103921
103972
  type: "chat"
@@ -104077,7 +104128,8 @@ const ChatMessage = reactExports.memo(function({
104077
104128
  companyColor,
104078
104129
  attachment,
104079
104130
  file,
104080
- togglePDFView
104131
+ togglePDFView,
104132
+ toggleVideoView: toggleVideoView2
104081
104133
  }) : /* @__PURE__ */ jsx(OtherUserMessage, {
104082
104134
  msg,
104083
104135
  attachment,
@@ -104090,9 +104142,11 @@ const SenderMessage = ({
104090
104142
  companyColor,
104091
104143
  attachment,
104092
104144
  file,
104093
- togglePDFView
104145
+ togglePDFView,
104146
+ toggleVideoView: toggleVideoView2
104094
104147
  }) => {
104095
104148
  var _a;
104149
+ const fileType = isFileType(file == null ? void 0 : file.ext);
104096
104150
  return /* @__PURE__ */ jsx("div", {
104097
104151
  className: "chat-send-container flex flex-col my-2",
104098
104152
  children: ((_a = msg.message) == null ? void 0 : _a.length) ? /* @__PURE__ */ jsxs(Fragment, {
@@ -104120,7 +104174,7 @@ const SenderMessage = ({
104120
104174
  })]
104121
104175
  })]
104122
104176
  }) : !!attachment ? /* @__PURE__ */ jsxs(Fragment, {
104123
- children: [isFileType(file.ext) === "image" ? /* @__PURE__ */ jsx("p", {
104177
+ children: [fileType === "image" ? /* @__PURE__ */ jsx("p", {
104124
104178
  className: "widget-chat-send widget-chat-file",
104125
104179
  children: /* @__PURE__ */ jsx("a", {
104126
104180
  target: "_blank",
@@ -104133,7 +104187,7 @@ const SenderMessage = ({
104133
104187
  alt: file.name
104134
104188
  })
104135
104189
  })
104136
- }) : isFileType(file.ext) === "document" ? /* @__PURE__ */ jsxs("div", {
104190
+ }) : fileType === "document" ? /* @__PURE__ */ jsxs("div", {
104137
104191
  className: "my-2 ml-auto widget-chat-file px-2 py-2",
104138
104192
  children: [/* @__PURE__ */ jsx("p", {
104139
104193
  className: "text-black",
@@ -104143,15 +104197,22 @@ const SenderMessage = ({
104143
104197
  className: "px-3 py-1 text-sm inline-block text-center font-medium rounded bg-blue-500 text-white hover:bg-blue-600 focus:ring-2 focus:ring-blue-300",
104144
104198
  children: "View Document"
104145
104199
  })]
104146
- }) : isFileType(file.ext) === "video" && /* @__PURE__ */ jsxs("div", {
104200
+ }) : fileType === "video" ? /* @__PURE__ */ jsxs("div", {
104147
104201
  className: "my-2 ml-auto widget-chat-file px-2 py-2",
104148
104202
  children: [/* @__PURE__ */ jsx("p", {
104149
104203
  className: "text-black",
104150
104204
  children: attachment == null ? void 0 : attachment.split("/").pop()
104151
104205
  }), /* @__PURE__ */ jsx(Button$1, {
104152
- onClick: () => toggleVideoView(attachment),
104206
+ onClick: () => toggleVideoView2(attachment),
104153
104207
  children: "Watch Video"
104154
104208
  })]
104209
+ }) : fileType === "audio" && /* @__PURE__ */ jsx("div", {
104210
+ className: "my-2 ml-auto widget-chat-file px-2 py-2",
104211
+ children: /* @__PURE__ */ jsx("audio", {
104212
+ controls: true,
104213
+ src: attachment,
104214
+ width: "100%"
104215
+ })
104155
104216
  }), /* @__PURE__ */ jsxs("div", {
104156
104217
  className: "flex items-center ml-auto",
104157
104218
  children: [/* @__PURE__ */ jsx("small", {
@@ -104182,6 +104243,7 @@ const OtherUserMessage = ({
104182
104243
  togglePDFView
104183
104244
  }) => {
104184
104245
  var _a, _b, _c, _d;
104246
+ const fileType = isFileType(file == null ? void 0 : file.ext);
104185
104247
  return /* @__PURE__ */ jsxs("div", {
104186
104248
  className: "chat-receive-container mb-2 flex items-center",
104187
104249
  children: [/* @__PURE__ */ jsxs("div", {
@@ -104199,7 +104261,7 @@ const OtherUserMessage = ({
104199
104261
  })]
104200
104262
  }), !!attachment ? /* @__PURE__ */ jsxs("div", {
104201
104263
  className: "my-2",
104202
- children: [isFileType(file.ext) === "image" ? /* @__PURE__ */ jsx("p", {
104264
+ children: [fileType === "image" ? /* @__PURE__ */ jsx("p", {
104203
104265
  className: `widget-chat-file mb-0`,
104204
104266
  children: /* @__PURE__ */ jsx("a", {
104205
104267
  target: "_blank",
@@ -104212,7 +104274,7 @@ const OtherUserMessage = ({
104212
104274
  alt: ""
104213
104275
  })
104214
104276
  })
104215
- }) : isFileType(file.ext) === "document" ? /* @__PURE__ */ jsxs("div", {
104277
+ }) : fileType === "document" ? /* @__PURE__ */ jsxs("div", {
104216
104278
  className: "widget-chat-file px-2 py-2",
104217
104279
  children: [/* @__PURE__ */ jsx("div", {
104218
104280
  className: "text-black",
@@ -104222,7 +104284,7 @@ const OtherUserMessage = ({
104222
104284
  className: "px-3 py-1 text-sm inline-block text-center font-medium rounded bg-blue-500 text-white hover:bg-blue-600 focus:ring-2 focus:ring-blue-300",
104223
104285
  children: "View Document"
104224
104286
  })]
104225
- }) : isFileType(file.ext) === "video" && /* @__PURE__ */ jsxs("div", {
104287
+ }) : fileType === "video" ? /* @__PURE__ */ jsxs("div", {
104226
104288
  className: "widget-chat-file px-2 py-2",
104227
104289
  children: [/* @__PURE__ */ jsx("p", {
104228
104290
  className: "text-black",
@@ -104231,6 +104293,13 @@ const OtherUserMessage = ({
104231
104293
  onClick: () => toggleVideoView(attachment),
104232
104294
  children: "Watch Video"
104233
104295
  })]
104296
+ }) : fileType === "audio" && /* @__PURE__ */ jsx("div", {
104297
+ className: "widget-chat-file px-2 py-2",
104298
+ children: /* @__PURE__ */ jsx("audio", {
104299
+ controls: true,
104300
+ src: attachment,
104301
+ width: "100%"
104302
+ })
104234
104303
  }), !!attachment && /* @__PURE__ */ jsx("small", {
104235
104304
  style: {
104236
104305
  fontSize: 10