Skip to content

Commit

Permalink
Adds helper to clarify supported phone number types in phone number f…
Browse files Browse the repository at this point in the history
…ield
  • Loading branch information
rithviknishad committed Jul 8, 2024
1 parent 15efeab commit 73a4a39
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
41 changes: 18 additions & 23 deletions src/Components/Form/FormFields/PhoneNumberFormField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ import {
formatPhoneNumber as formatPhoneNumberUtil,
getCountryCode,
CountryData,
humanizeStrings,
} from "../../../Utils/utils";
import phoneCodesJson from "../../../Common/static/countryPhoneAndFlags.json";
import {
FieldError,
PhoneNumberValidator,
PhoneNumberType,
} from "../FieldValidators";
import CareIcon, { IconName } from "../../../CAREUI/icons/CareIcon";
import CareIcon from "../../../CAREUI/icons/CareIcon";
import { Popover } from "@headlessui/react";
import { useTranslation } from "react-i18next";

const phoneCodes: Record<string, CountryData> = phoneCodesJson;

Expand Down Expand Up @@ -154,29 +156,22 @@ export default function PhoneNumberFormField(props: Props) {
);
}

const phoneNumberTypeIcons: Record<PhoneNumberType, IconName> = {
international_mobile: "l-globe",
indian_mobile: "l-mobile-android",
mobile: "l-mobile-android",
landline: "l-phone",
support: "l-headset",
};
const PhoneNumberTypesHelp = (props: { types: PhoneNumberType[] }) => {
const { t } = useTranslation();

const PhoneNumberTypesHelp = ({ types }: { types: PhoneNumberType[] }) => (
<div className="flex gap-1">
{types.map((type) => (
<span key={type} className="tooltip mt-1">
<CareIcon
icon={phoneNumberTypeIcons[type]}
className="text-lg text-gray-500"
/>
<span className="tooltip-text tooltip-bottom -translate-x-1/2 translate-y-1 text-xs capitalize">
{type.replace("_", " ")}
</span>
</span>
))}
</div>
);
return (
<div className="tooltip mt-1 pr-1 text-gray-500">
<CareIcon icon="l-question-circle" className="text-lg" />
<div className="tooltip-text tooltip-left text-sm">
Supports only{" "}
<span className="font-bold lowercase">
{humanizeStrings(...props.types.map((item) => t(item)))}
</span>{" "}
numbers.
</div>
</div>
);
};

const conditionPhoneCode = (code: string) => {
code = code.split(" ")[0];
Expand Down
5 changes: 5 additions & 0 deletions src/Locale/en/Common.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
"filter": "Filter",
"ordering": "Ordering",
"phone_number": "Phone Number",
"international_mobile": "International Mobile",
"indian_mobile": "Indian Mobile",
"mobile": "Mobile",
"landline": "Indian landline",
"support": "Support",
"emergency_contact_number": "Emergency Contact Number",
"last_modified": "Last Modified",
"patient_address": "Patient Address",
Expand Down

0 comments on commit 73a4a39

Please sign in to comment.