Skip to content

Commit

Permalink
Merge branch 'develop' into issue/9733/user-create-edit
Browse files Browse the repository at this point in the history
  • Loading branch information
rajku-dev authored Jan 14, 2025
2 parents 6d0901f + 1833fb6 commit bb3919b
Show file tree
Hide file tree
Showing 30 changed files with 1,277 additions and 716 deletions.
5 changes: 2 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions public/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,7 @@
"create_new_abha_address": "Create New ABHA Address",
"create_new_abha_profile": "Don't have an ABHA Number",
"create_new_asset": "Create New Asset",
"create_new_encounter": "Create a new encounter to get started",
"create_new_tag": "Create New Tag",
"create_position_preset": "Create a new position preset",
"create_position_preset_description": "Creates a new position preset in Care from the current position of the camera for the given name",
Expand Down Expand Up @@ -942,6 +943,7 @@
"encounter_suggestion_edit_disallowed": "Not allowed to switch to this option in edit consultation",
"encounters": "Encounters",
"end_datetime": "End Date/Time",
"end_dose": "End Dose",
"end_time": "End Time",
"enter_aadhaar_number": "Enter a 12-digit Aadhaar ID",
"enter_aadhaar_otp": "Enter OTP sent to the registered mobile with Aadhaar",
Expand Down Expand Up @@ -1072,6 +1074,7 @@
"get_auth_methods": "Get Available Authentication Methods",
"get_auth_mode_error": "Could not find any supported authentication methods, Please try again with a different authentication method",
"get_tests": "Get Tests",
"go_back": "Go Back",
"goal": "Our goal is to continuously improve the quality and accessibility of public healthcare services using digital tools.",
"granted_on": "Granted On",
"has_allergies": "Has Allergies",
Expand Down Expand Up @@ -1567,6 +1570,7 @@
"please_confirm_password": "Please confirm your new password.",
"please_enter_a_reason_for_the_shift": "Please enter a reason for the shift.",
"please_enter_confirm_password": "Please confirm your new password",
"please_enter_correct_birth_year": "Please enter the correct birth year to verify the patient details.",
"please_enter_current_password": "Please enter your current password.",
"please_enter_new_password": "Please enter your new password.",
"please_enter_username": "Please enter the username",
Expand Down Expand Up @@ -1931,6 +1935,8 @@
"start_date": "Start Date",
"start_datetime": "Start Date/Time",
"start_dosage": "Start Dosage",
"start_dose": "Start Dose",
"start_new_clinical_encounter": "Start a new clinical encounter",
"start_review": "Start Review",
"start_time": "Start Time",
"start_time_must_be_before_end_time": "Start time must be before end time",
Expand Down Expand Up @@ -1962,6 +1968,7 @@
"tachycardia": "Tachycardia",
"tag_name": "Tag Name",
"tag_slug": "Tag Slug",
"taper_titrate_dosage": "Taper & Titrate Dosage",
"target_dosage": "Target Dosage",
"template_deleted": "Template has been deleted",
"test_type": "Type of test done",
Expand Down Expand Up @@ -2028,6 +2035,8 @@
"unit_mo": "Months",
"unit_ms": "Milliseconds",
"unit_s": "Seconds",
"unit_taper": "Taper",
"unit_titrate": "Titrate",
"unit_tsp": "Tsp",
"unit_unit(s)": "Unit(s)",
"unit_wk": "Weeks",
Expand Down Expand Up @@ -2136,6 +2145,7 @@
"ventilator_oxygen_modality": "Oxygen Modality",
"ventilator_oxygen_modality_oxygen_rate": "Oxygen Flow Rate",
"ventilator_spo2": "SpO₂",
"verification_failed": "Verification Failed",
"verify": "Verify",
"verify_and_link": "Verify and Link",
"verify_otp": "Verify OTP",
Expand Down
7 changes: 6 additions & 1 deletion src/Utils/request/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,15 @@ export async function callApi<Route extends ApiRoute<unknown, unknown>>(
const data = await getResponseBody<Route["TRes"]>(res);

if (!res.ok) {
const isSilent =
typeof options?.silent === "function"
? options.silent(res)
: (options?.silent ?? false);

throw new HTTPError({
message: "Request Failed",
status: res.status,
silent: options?.silent ?? false,
silent: isSilent,
cause: data as unknown as Record<string, unknown>,
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/Utils/request/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export interface ApiCallOptions<Route extends ApiRoute<unknown, unknown>> {
pathParams?: PathParams<Route["path"]>;
queryParams?: QueryParams;
body?: Route["TBody"];
silent?: boolean;
silent?: boolean | ((response: Response) => boolean);
signal?: AbortSignal;
headers?: HeadersInit;
}
Expand Down
130 changes: 59 additions & 71 deletions src/components/Common/Avatar.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,31 @@
import * as AvatarPrimitive from "@radix-ui/react-avatar";
import React from "react";

import { cn } from "@/lib/utils";

const colors: string[] = [
"#E6F3FF", // Light Blue
"#FFF0E6", // Light Peach
"#E6FFE6", // Light Green
"#FFE6E6", // Light Pink
"#F0E6FF", // Light Purple
"#FFFFE6", // Light Yellow
"#E6FFFF", // Light Cyan
"#FFE6F3", // Light Rose
"#F3FFE6", // Light Lime
"#E6E6FF", // Light Lavender
"#FFE6FF", // Light Magenta
"#E6FFF0", // Light Mint
// Subtle, professional color combinations that blend well with the UI
const colorPairs: Array<[string, string]> = [
["#E3F2FD", "#1565C0"], // Subtle Blue
["#E8F5E9", "#2E7D32"], // Subtle Green
["#FFF3E0", "#E65100"], // Subtle Orange
["#F3E5F5", "#6A1B9A"], // Subtle Purple
["#E1F5FE", "#0277BD"], // Subtle Light Blue
["#E0F2F1", "#00695C"], // Subtle Teal
["#FBE9E7", "#D84315"], // Subtle Deep Orange
["#F3E5F5", "#6A1B9A"], // Subtle Purple
["#E8EAF6", "#283593"], // Subtle Indigo
["#FFF8E1", "#FF8F00"], // Subtle Amber
["#FCE4EC", "#C2185B"], // Subtle Pink
["#EFEBE9", "#4E342E"], // Subtle Brown
];

const stringToInt = (name: string): number => {
const aux = (sum: number, remains: string): number => {
if (remains === "") return sum;
const firstCharacter = remains.slice(0, 1);
const newRemains = remains.slice(1);
return aux(sum + firstCharacter.charCodeAt(0), newRemains);
};

return Math.floor(aux(0, name));
const stringToIndex = (name: string): number => {
return name.split("").reduce((acc, char) => acc + char.charCodeAt(0), 0);
};

const toColor = (name: string): [string, string] => {
const index = stringToInt(name) % colors.length;
const backgroundColor = colors[index];
return [backgroundColor, "#333333"]; // Using dark gray for text
const getColorPair = (name: string): [string, string] => {
const index = stringToIndex(name) % colorPairs.length;
return colorPairs[index];
};

const initials = (name: string): string => {
Expand All @@ -40,73 +34,67 @@ const initials = (name: string): string => {
.slice(0, 2)
.map((word) => word.slice(0, 1))
.join("")
.toUpperCase(); // Ensure initials are uppercase
.toUpperCase();
};

interface AvatarProps {
colors?: [string, string];
name?: string;
name: string;
imageUrl?: string;
className?: string;
icon?: React.ReactNode;
}

const Avatar: React.FC<AvatarProps> = ({
colors: propColors,
name,
imageUrl,
className,
icon,
}) => {
const [bgColor] = propColors || (name ? toColor(name) : toColor(""));
const Avatar = React.forwardRef<
React.ElementRef<typeof AvatarPrimitive.Root>,
AvatarProps
>(({ colors: propColors, name, imageUrl, className }, ref) => {
const avatarText = name.match(/[a-zA-Z]+/g)?.join(" ");

const [bgColor, textColor] =
propColors ||
(avatarText ? getColorPair(avatarText) : getColorPair("user"));

return (
<div
title={name}
className={cn(
`flex aspect-square w-full items-center justify-center overflow-hidden border border-black/10`,
className,
)}
<AvatarPrimitive.Root
ref={ref}
className={cn("w-full h-full", className)}
style={{
background: bgColor,
borderRadius: "calc(100% / 15)",
}}
>
{imageUrl ? (
<img
<AvatarPrimitive.Image
src={imageUrl}
alt={name}
className="aspect-square h-full w-full object-cover"
/>
) : icon ? (
<div className="flex items-center justify-center w-full h-full">
{icon}
</div>
) : (
// Render initials SVG
<svg
xmlns="http://www.w3.org/2000/svg"
version="1.1"
viewBox="0 0 100 100"
className="aspect-square h-full w-full object-cover"
>
<text
fill="black"
fillOpacity="0.1"
fontSize="40"
fontWeight="900"
x="50"
y="54"
textAnchor="middle"
dominantBaseline="middle"
alignmentBaseline="middle"
<AvatarPrimitive.Fallback className="flex h-full w-full select-none items-center justify-center text-center">
<svg
xmlns="http://www.w3.org/2000/svg"
version="1.1"
viewBox="0 0 100 100"
className="aspect-square h-full w-full object-cover"
>
{name ? initials(name) : null}
</text>
</svg>
<text
fill={textColor}
fillOpacity="0.5"
fontSize="50"
fontWeight="900"
x="50"
y="54"
textAnchor="middle"
dominantBaseline="middle"
alignmentBaseline="middle"
>
{avatarText ? initials(avatarText) : null}
</text>
</svg>
</AvatarPrimitive.Fallback>
)}
</div>
</AvatarPrimitive.Root>
);
};
});

export { Avatar };
export type { AvatarProps };
Loading

0 comments on commit bb3919b

Please sign in to comment.