@medplum/react 0.9.19 → 0.9.20

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/cjs/index.js CHANGED
@@ -25,7 +25,7 @@
25
25
  const className = 'medplum-input';
26
26
  const issues = getIssuesForExpression(props.outcome, props.name);
27
27
  const invalid = issues && issues.length > 0;
28
- return (React__default["default"].createElement("input", { id: props.name, name: props.name, type: getInputType(props.type), size: props.size, step: props.step, className: className, defaultValue: props.defaultValue || '', required: props.required, autoCapitalize: props.autoCapitalize, autoComplete: props.autoComplete, autoFocus: props.autoFocus, ref: props.inputRef, "aria-invalid": invalid, "aria-describedby": invalid ? props.name + '-errors' : '', placeholder: props.placeholder, "data-testid": props.testid, disabled: props.disabled, onChange: (e) => {
28
+ return (React__default["default"].createElement("input", { id: props.name, name: props.name, type: getInputType(props.type), size: props.size, step: props.step, className: className, style: props.style, defaultValue: props.defaultValue || '', required: props.required, autoCapitalize: props.autoCapitalize, autoComplete: props.autoComplete, autoFocus: props.autoFocus, ref: props.inputRef, "aria-invalid": invalid, "aria-describedby": invalid ? props.name + '-errors' : '', placeholder: props.placeholder, "data-testid": props.testid, disabled: props.disabled, onChange: (e) => {
29
29
  if (props.onChange) {
30
30
  props.onChange(e.currentTarget.value);
31
31
  }
@@ -876,6 +876,18 @@
876
876
  return React__default["default"].createElement(React__default["default"].Fragment, null, builder.join('').trim());
877
877
  }
878
878
 
879
+ function ContactDetailDisplay(props) {
880
+ var _a;
881
+ const contactDetail = props.value;
882
+ if (!contactDetail) {
883
+ return null;
884
+ }
885
+ return (React__default["default"].createElement(React__default["default"].Fragment, null,
886
+ contactDetail.name,
887
+ contactDetail.name && ': ', (_a = contactDetail.telecom) === null || _a === void 0 ? void 0 :
888
+ _a.map((telecom, index) => (React__default["default"].createElement(ContactPointDisplay, { key: 'telecom-' + index, value: telecom })))));
889
+ }
890
+
879
891
  function DateTimeDisplay(props) {
880
892
  if (!props.value) {
881
893
  return null;
@@ -1024,6 +1036,8 @@
1024
1036
  return React__default["default"].createElement(CodeableConceptDisplay, { value: value });
1025
1037
  case core.PropertyType.Coding:
1026
1038
  return React__default["default"].createElement(CodingDisplay, { value: value });
1039
+ case core.PropertyType.ContactDetail:
1040
+ return React__default["default"].createElement(ContactDetailDisplay, { value: value });
1027
1041
  case core.PropertyType.ContactPoint:
1028
1042
  return React__default["default"].createElement(ContactPointDisplay, { value: value });
1029
1043
  case core.PropertyType.HumanName:
@@ -1193,19 +1207,34 @@
1193
1207
  const ref = React.useRef();
1194
1208
  ref.current = contactPoint;
1195
1209
  function setContactPointWrapper(newValue) {
1210
+ if (newValue && Object.keys(newValue).length === 0) {
1211
+ newValue = undefined;
1212
+ }
1196
1213
  setContactPoint(newValue);
1197
1214
  if (props.onChange) {
1198
1215
  props.onChange(newValue);
1199
1216
  }
1200
1217
  }
1201
1218
  function setSystem(system) {
1202
- setContactPointWrapper(Object.assign(Object.assign({}, ref.current), { system: system ? system : undefined }));
1219
+ const newValue = Object.assign(Object.assign({}, ref.current), { system });
1220
+ if (!system) {
1221
+ delete newValue.system;
1222
+ }
1223
+ setContactPointWrapper(newValue);
1203
1224
  }
1204
1225
  function setUse(use) {
1205
- setContactPointWrapper(Object.assign(Object.assign({}, ref.current), { use: use ? use : undefined }));
1226
+ const newValue = Object.assign(Object.assign({}, ref.current), { use });
1227
+ if (!use) {
1228
+ delete newValue.use;
1229
+ }
1230
+ setContactPointWrapper(newValue);
1206
1231
  }
1207
1232
  function setValue(value) {
1208
- setContactPointWrapper(Object.assign(Object.assign({}, ref.current), { value: value ? value : undefined }));
1233
+ const newValue = Object.assign(Object.assign({}, ref.current), { value });
1234
+ if (!value) {
1235
+ delete newValue.value;
1236
+ }
1237
+ setContactPointWrapper(newValue);
1209
1238
  }
1210
1239
  return (React__default["default"].createElement(InputRow, null,
1211
1240
  React__default["default"].createElement(Select, { defaultValue: contactPoint === null || contactPoint === void 0 ? void 0 : contactPoint.system, onChange: setSystem, testid: "system" },
@@ -1226,6 +1255,36 @@
1226
1255
  React__default["default"].createElement(Input, { placeholder: "Value", defaultValue: contactPoint === null || contactPoint === void 0 ? void 0 : contactPoint.value, onChange: setValue })));
1227
1256
  }
1228
1257
 
1258
+ function ContactDetailInput(props) {
1259
+ var _a;
1260
+ const [contactPoint, setContactDetail] = React.useState(props.defaultValue);
1261
+ const ref = React.useRef();
1262
+ ref.current = contactPoint;
1263
+ function setContactDetailWrapper(newValue) {
1264
+ setContactDetail(newValue);
1265
+ if (props.onChange) {
1266
+ props.onChange(newValue);
1267
+ }
1268
+ }
1269
+ function setName(name) {
1270
+ const newValue = Object.assign(Object.assign({}, ref.current), { name });
1271
+ if (!name) {
1272
+ delete newValue.name;
1273
+ }
1274
+ setContactDetailWrapper(newValue);
1275
+ }
1276
+ function setTelecom(telecom) {
1277
+ const newValue = Object.assign(Object.assign({}, ref.current), { telecom: telecom && [telecom] });
1278
+ if (!telecom) {
1279
+ delete newValue.telecom;
1280
+ }
1281
+ setContactDetailWrapper(newValue);
1282
+ }
1283
+ return (React__default["default"].createElement(InputRow, null,
1284
+ React__default["default"].createElement(Input, { name: props.name + '-name', placeholder: "Name", style: { width: 180 }, defaultValue: contactPoint === null || contactPoint === void 0 ? void 0 : contactPoint.name, onChange: setName }),
1285
+ React__default["default"].createElement(ContactPointInput, { name: props.name + '-telecom', defaultValue: (_a = contactPoint === null || contactPoint === void 0 ? void 0 : contactPoint.telecom) === null || _a === void 0 ? void 0 : _a[0], onChange: setTelecom })));
1286
+ }
1287
+
1229
1288
  /**
1230
1289
  * The DateTimeInput component is a wrapper around the HTML5 input type="datetime-local".
1231
1290
  * The main purpose is to reconcile time zones.
@@ -1640,6 +1699,8 @@
1640
1699
  return React__default["default"].createElement(CodeableConceptInput, { property: property, name: name, defaultValue: value, onChange: props.onChange });
1641
1700
  case core.PropertyType.Coding:
1642
1701
  return React__default["default"].createElement(CodingInput, { property: property, name: name, defaultValue: value, onChange: props.onChange });
1702
+ case core.PropertyType.ContactDetail:
1703
+ return React__default["default"].createElement(ContactDetailInput, { name: name, defaultValue: value, onChange: props.onChange });
1643
1704
  case core.PropertyType.ContactPoint:
1644
1705
  return React__default["default"].createElement(ContactPointInput, { name: name, defaultValue: value, onChange: props.onChange });
1645
1706
  case core.PropertyType.Extension:
@@ -5232,7 +5293,7 @@
5232
5293
 
5233
5294
  function GoogleButton(props) {
5234
5295
  const medplum = useMedplum();
5235
- const { handleAuthResponse } = props;
5296
+ const { handleGoogleCredential } = props;
5236
5297
  const googleClientId = getGoogleClientId(props.googleClientId);
5237
5298
  const parentRef = React.useRef(null);
5238
5299
  const [scriptLoaded, setScriptLoaded] = React.useState(typeof google !== 'undefined');
@@ -5246,7 +5307,7 @@
5246
5307
  if (!initialized) {
5247
5308
  google.accounts.id.initialize({
5248
5309
  client_id: googleClientId,
5249
- callback: (response) => medplum.startGoogleLogin(response).then(handleAuthResponse),
5310
+ callback: handleGoogleCredential,
5250
5311
  });
5251
5312
  setInitialized(true);
5252
5313
  }
@@ -5254,7 +5315,7 @@
5254
5315
  google.accounts.id.renderButton(parentRef.current, {});
5255
5316
  setButtonRendered(true);
5256
5317
  }
5257
- }, [medplum, googleClientId, initialized, scriptLoaded, parentRef, buttonRendered, handleAuthResponse]);
5318
+ }, [medplum, googleClientId, initialized, scriptLoaded, parentRef, buttonRendered, handleGoogleCredential]);
5258
5319
  if (!googleClientId) {
5259
5320
  return null;
5260
5321
  }
@@ -5285,19 +5346,24 @@
5285
5346
  setMemberships(response.memberships);
5286
5347
  }
5287
5348
  if (response.code) {
5288
- medplum
5289
- .processCode(response.code)
5290
- .then(() => {
5291
- if (props.onSuccess) {
5292
- props.onSuccess();
5293
- }
5294
- })
5295
- .catch(console.log);
5349
+ if (props.onCode) {
5350
+ props.onCode(response.code);
5351
+ }
5352
+ else {
5353
+ medplum
5354
+ .processCode(response.code)
5355
+ .then(() => {
5356
+ if (props.onSuccess) {
5357
+ props.onSuccess();
5358
+ }
5359
+ })
5360
+ .catch(console.log);
5361
+ }
5296
5362
  }
5297
5363
  }
5298
5364
  return (React__default["default"].createElement(Document, { width: 450 }, (() => {
5299
5365
  if (!login) {
5300
- return (React__default["default"].createElement(AuthenticationForm, { googleClientId: props.googleClientId, onForgotPassword: props.onForgotPassword, onRegister: props.onRegister, handleAuthResponse: handleAuthResponse }, props.children));
5366
+ return (React__default["default"].createElement(AuthenticationForm, { clientId: props.clientId, scope: props.scope, nonce: props.nonce, googleClientId: props.googleClientId, onForgotPassword: props.onForgotPassword, onRegister: props.onRegister, handleAuthResponse: handleAuthResponse }, props.children));
5301
5367
  }
5302
5368
  else if (memberships) {
5303
5369
  return React__default["default"].createElement(ProfileForm, { login: login, memberships: memberships, handleAuthResponse: handleAuthResponse });
@@ -5314,6 +5380,9 @@
5314
5380
  return (React__default["default"].createElement(Form, { style: { maxWidth: 400 }, onSubmit: (formData) => {
5315
5381
  medplum
5316
5382
  .startLogin({
5383
+ clientId: props.clientId,
5384
+ scope: props.scope,
5385
+ nonce: props.nonce,
5317
5386
  email: formData.email,
5318
5387
  password: formData.password,
5319
5388
  remember: formData.remember === 'true',
@@ -5340,7 +5409,18 @@
5340
5409
  React__default["default"].createElement("div", null,
5341
5410
  React__default["default"].createElement(Button, { type: "submit", testid: "submit" }, "Sign in"))),
5342
5411
  React__default["default"].createElement("div", { className: "medplum-signin-google-container" },
5343
- React__default["default"].createElement(GoogleButton, { googleClientId: props.googleClientId, handleAuthResponse: props.handleAuthResponse }))));
5412
+ React__default["default"].createElement(GoogleButton, { googleClientId: props.googleClientId, handleGoogleCredential: (response) => {
5413
+ medplum
5414
+ .startGoogleLogin({
5415
+ clientId: props.clientId,
5416
+ scope: props.scope,
5417
+ nonce: props.nonce,
5418
+ googleClientId: response.clientId,
5419
+ googleCredential: response.credential,
5420
+ })
5421
+ .then(props.handleAuthResponse)
5422
+ .catch(setOutcome);
5423
+ } }))));
5344
5424
  }
5345
5425
  function ProfileForm(props) {
5346
5426
  const medplum = useMedplum();
@@ -5426,6 +5506,8 @@
5426
5506
  exports.CodeInput = CodeInput;
5427
5507
  exports.CodeableConceptDisplay = CodeableConceptDisplay;
5428
5508
  exports.CodeableConceptInput = CodeableConceptInput;
5509
+ exports.ContactDetailDisplay = ContactDetailDisplay;
5510
+ exports.ContactDetailInput = ContactDetailInput;
5429
5511
  exports.ContactPointDisplay = ContactPointDisplay;
5430
5512
  exports.ContactPointInput = ContactPointInput;
5431
5513
  exports.DateTimeDisplay = DateTimeDisplay;