@jobber/components-native 0.45.0 → 0.46.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jobber/components-native",
3
- "version": "0.45.0",
3
+ "version": "0.46.0",
4
4
  "license": "MIT",
5
5
  "description": "React Native implementation of Atlantis",
6
6
  "repository": {
@@ -84,5 +84,5 @@
84
84
  "react-native-reanimated": "^2.17.0",
85
85
  "react-native-safe-area-context": "^4.5.2"
86
86
  },
87
- "gitHead": "90e9d2a124e1d65d678364063f6ef57e066939af"
87
+ "gitHead": "6ff59b16b38fdf784fa15bcfa41eb97181d2f6b0"
88
88
  }
@@ -1,18 +1,18 @@
1
1
  import React from "react";
2
- import { useIntl } from "react-intl";
3
2
  import { Platform } from "react-native";
4
3
  import { onLongPressLink, onPressLink } from "../../utils";
5
4
  import { Link } from "../Link/Link";
6
5
  import { Text } from "../../../Text";
6
+ import { useAtlantisI18n } from "../../../hooks/useAtlantisI18n";
7
7
  export function ComposeTextWithLinks({ part, index, match, bottomTabsVisible, selectable = true, }) {
8
- const { formatMessage } = useIntl();
8
+ const { t } = useAtlantisI18n();
9
9
  const isLink = match === null || match === void 0 ? void 0 : match.getType();
10
10
  if (isLink) {
11
11
  return (React.createElement(Link, { key: index, onPress: () => onPressLink(match), onLongPress: () => {
12
12
  if (selectable && Platform.OS === "android") {
13
13
  return;
14
14
  }
15
- onLongPressLink(match, bottomTabsVisible, formatMessage);
15
+ onLongPressLink(match, bottomTabsVisible, t);
16
16
  } }, match.getAnchorText()));
17
17
  }
18
18
  return React.createElement(Text, { key: index }, part);
@@ -1,5 +1,4 @@
1
1
  import { Linking } from "react-native";
2
- import { messages } from "./messages";
3
2
  import { copyTextToClipboard } from "./clipboard";
4
3
  function hasPrefix(text, prefixes) {
5
4
  return prefixes.some(prefix => text.includes(prefix));
@@ -31,10 +30,10 @@ export function getUrl(match, immediateOpen = true) {
31
30
  return match.getAnchorHref();
32
31
  }
33
32
  }
34
- export function onLongPressLink(match, bottomTabsVisible, formatMessage) {
33
+ export function onLongPressLink(match, bottomTabsVisible, t) {
35
34
  const linkUrl = getUrl(match, false);
36
35
  const toastConfig = {
37
- message: formatMessage(messages[`${match.getType()}Copied`]),
36
+ message: t(getMessageKey(match)),
38
37
  bottomTabsVisible,
39
38
  };
40
39
  copyTextToClipboard(linkUrl, toastConfig);
@@ -43,3 +42,15 @@ export function onPressLink(match) {
43
42
  const linkUrl = getUrl(match);
44
43
  Linking.openURL(linkUrl);
45
44
  }
45
+ function getMessageKey(match) {
46
+ switch (match.getType()) {
47
+ case "email":
48
+ return "AutoLink.emailCopied";
49
+ case "phone":
50
+ return "AutoLink.phoneCopied";
51
+ case "url":
52
+ return "AutoLink.urlCopied";
53
+ default:
54
+ return "copied";
55
+ }
56
+ }
@@ -1,11 +1,8 @@
1
1
  import React, { useMemo, useState } from "react";
2
2
  import DateTimePicker from "react-native-modal-datetime-picker";
3
3
  import { Platform } from "react-native";
4
- import { utcToZonedTime } from "date-fns-tz";
5
- import { format as formatDate } from "date-fns";
6
4
  import { FormField } from "../FormField";
7
5
  import { InputPressable } from "../InputPressable";
8
- import { useAtlantisContext } from "../AtlantisContext";
9
6
  import { useAtlantisI18n } from "../hooks/useAtlantisI18n";
10
7
  function formatInvalidState(error, invalid) {
11
8
  if (invalid)
@@ -32,8 +29,7 @@ export function InputDate(props) {
32
29
  }
33
30
  function InternalInputDate({ clearable = "always", disabled, emptyValueLabel, invalid, maxDate, minDate, placeholder, value, name, onChange, accessibilityLabel, accessibilityHint, }) {
34
31
  const [showPicker, setShowPicker] = useState(false);
35
- const { t, locale } = useAtlantisI18n();
36
- const { timeZone, dateFormat } = useAtlantisContext();
32
+ const { t, locale, formatDate } = useAtlantisI18n();
37
33
  const date = useMemo(() => {
38
34
  if (typeof value === "string")
39
35
  return new Date(value);
@@ -41,11 +37,10 @@ function InternalInputDate({ clearable = "always", disabled, emptyValueLabel, in
41
37
  }, [value]);
42
38
  const formattedDate = useMemo(() => {
43
39
  if (date) {
44
- const zonedTime = utcToZonedTime(date, timeZone);
45
- return formatDate(zonedTime, dateFormat);
40
+ return formatDate(date);
46
41
  }
47
42
  return emptyValueLabel;
48
- }, [date, emptyValueLabel, timeZone, dateFormat]);
43
+ }, [date, emptyValueLabel]);
49
44
  const canClearDate = formattedDate === emptyValueLabel ? "never" : clearable;
50
45
  const placeholderLabel = placeholder !== null && placeholder !== void 0 ? placeholder : t("date");
51
46
  return (React.createElement(React.Fragment, null,
@@ -1,8 +1,6 @@
1
1
  import React, { useMemo, useState } from "react";
2
2
  import DateTimePicker from "react-native-modal-datetime-picker";
3
3
  import { View } from "react-native";
4
- import { utcToZonedTime } from "date-fns-tz";
5
- import { format as formatTime } from "date-fns";
6
4
  import { styles } from "./InputTime.style";
7
5
  import { getTimeZoneOffsetInMinutes, roundUpToNearestMinutes } from "./utils";
8
6
  import { useAtlantisContext } from "../AtlantisContext";
@@ -32,17 +30,16 @@ export function InputTime(props) {
32
30
  }
33
31
  function InternalInputTime({ clearable = "always", disabled, emptyValueLabel, invalid, placeholder, value, name, type = "scheduling", onChange, showIcon = true, }) {
34
32
  const [showPicker, setShowPicker] = useState(false);
35
- const { t } = useAtlantisI18n();
33
+ const { t, formatTime } = useAtlantisI18n();
36
34
  const { timeZone, timeFormat } = useAtlantisContext();
37
35
  const is24Hour = timeFormat === "HH:mm";
38
36
  const dateTime = useMemo(() => (typeof value === "string" ? new Date(value) : value), [value]);
39
37
  const formattedTime = useMemo(() => {
40
38
  if (dateTime) {
41
- const zonedTime = utcToZonedTime(dateTime, timeZone);
42
- return formatTime(zonedTime, timeFormat);
39
+ return formatTime(dateTime);
43
40
  }
44
41
  return emptyValueLabel;
45
- }, [dateTime, emptyValueLabel, timeZone, timeFormat]);
42
+ }, [dateTime, emptyValueLabel]);
46
43
  const canClearTime = formattedTime === emptyValueLabel ? "never" : clearable;
47
44
  return (React.createElement(View, { style: styles.container },
48
45
  React.createElement(InputPressable, { clearable: canClearTime, disabled: disabled, invalid: invalid, placeholder: placeholder !== null && placeholder !== void 0 ? placeholder : t("time"), prefix: showIcon ? { icon: "timer" } : undefined, value: formattedTime, onClear: handleClear, onPress: showDatePicker }),
@@ -1,6 +1,10 @@
1
1
  {
2
+ "AutoLink.emailCopied": "Email copied",
3
+ "AutoLink.phoneCopied": "Phone number copied",
4
+ "AutoLink.urlCopied": "URL copied",
2
5
  "cancel": "Cancel",
3
6
  "confirm": "Confirm",
7
+ "copied": "Copied",
4
8
  "date": "Date",
5
9
  "dismiss": "Dismiss",
6
10
  "done": "Done",
@@ -1,6 +1,10 @@
1
1
  {
2
+ "AutoLink.emailCopied": "Correo electrónico copiado",
3
+ "AutoLink.phoneCopied": "Número de teléfono copiado",
4
+ "AutoLink.urlCopied": "URL copiada",
2
5
  "cancel": "Cancelar",
3
6
  "confirm": "Confirmar",
7
+ "copied": "Copiado",
4
8
  "date": "Fecha",
5
9
  "dismiss": "Descartar",
6
10
  "done": "Listo",
@@ -1,10 +1,14 @@
1
+ import { useCallback } from "react";
1
2
  import en from "./locales/en.json";
2
3
  import es from "./locales/es.json";
4
+ import { dateFormatter } from "./utils/dateFormatter";
3
5
  import { useAtlantisContext } from "../../AtlantisContext";
4
6
  export function useAtlantisI18n() {
5
- const { locale } = useAtlantisContext();
6
- const t = (messageKey, values) => formatMessage(messageKey, values, locale);
7
- return { locale, t };
7
+ const { locale, dateFormat, timeFormat, timeZone } = useAtlantisContext();
8
+ const t = useCallback((messageKey, values) => formatMessage(messageKey, values, locale), [formatMessage, locale]);
9
+ const formatDate = useCallback((date) => dateFormatter(date, dateFormat, { locale, timeZone }), [dateFormatter, locale]);
10
+ const formatTime = useCallback((date) => dateFormatter(date, timeFormat, { locale, timeZone }), [dateFormatter, locale]);
11
+ return { locale, t, formatDate, formatTime };
8
12
  }
9
13
  function getLocalizedStrings(locale) {
10
14
  switch (locale) {
@@ -0,0 +1,20 @@
1
+ import { format } from "date-fns";
2
+ import { utcToZonedTime } from "date-fns-tz";
3
+ import { es } from "date-fns/locale";
4
+ export function dateFormatter(date, dateTimeFormat, { locale, timeZone }) {
5
+ const zonedTime = utcToZonedTime(date, timeZone);
6
+ return format(zonedTime, dateTimeFormat, {
7
+ locale: getDateFnsLocale(locale),
8
+ });
9
+ }
10
+ /**
11
+ * Change locale string to date-fns locale object.
12
+ */
13
+ function getDateFnsLocale(locale) {
14
+ switch (locale) {
15
+ case "es":
16
+ return es;
17
+ default:
18
+ return;
19
+ }
20
+ }