Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions public/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,7 @@
"back_to_app_store": "Back to App Store",
"back_to_consultation": "Go back to Consultation",
"back_to_dispense_queue": "Back to Dispense Queue",
"back_to_email_reset": "Back to email reset",
"back_to_encounter": "Back to Encounter",
"back_to_facilities": "Back to Facilities",
"back_to_home": "Back to Home",
Expand Down Expand Up @@ -1110,6 +1111,7 @@
"cannot_select_month_out_of_range": "Cannot select month out of range",
"cannot_select_year_out_of_range": "Cannot select year out of range",
"cant_access_code": "Can't access your code?",
"cant_access_email": "Can't access your email?",
"cant_scan_copy_key": "Can't scan? <strong>Copy setup key</strong> <CareIcon /> to add it to your authenticator app.",
"cap": "Cap",
"capacity": "Capacity",
Expand Down Expand Up @@ -2698,6 +2700,8 @@
"footer_image": "Footer Image",
"forget_password": "Forgot password?",
"forget_password_instruction": "Enter your username, and if it exists, we will send you a link to reset your password.",
"forget_password_phone_instruction": "Enter your registered phone number, and if it exists, we will send you an OTP to reset your password.",
"forget_password_phone_otp_instruction": "Enter the OTP sent to your phone, then create and confirm your new password.",
"form_preview": "Form Preview",
"form_submission_discard_failed": "Failed to discard form submission",
"form_submission_discarded": "Form submission discarded",
Expand Down Expand Up @@ -3564,6 +3568,8 @@
"moving_camera": "Moving Camera",
"mrp": "MRP",
"multi_invoice": "Multi Invoice",
"multiple_users_linked_to_phone": "Multiple users linked to this phone number",
"multiple_users_linked_to_phone_hint": "Enter your username so we can reset the correct account.",
"must_be_greater_than_value": "Must be greater than {{value}}",
"my_dept": "My Dept.",
"my_doctors": "My Doctors",
Expand Down Expand Up @@ -4149,6 +4155,7 @@
"other_encounters": "Other Encounters",
"other_medications": "Other Medications",
"other_tags": "Other Tags",
"otp_password_reset_sent": "If this phone number is registered, you will receive an OTP.",
"otp_verification_error": "Failed to verify OTP. Please try again later.",
"otp_verification_success": "OTP has been verified successfully.",
"out": "out",
Expand Down Expand Up @@ -5012,6 +5019,7 @@
"reset_password_note_self": "Enter your current password, then create and confirm your new password",
"reset_pinned_links": "Reset Pinned Links",
"reset_to_default": "Reset to Default",
"reset_using_phone_number": "Reset using phone number",
"resolved": "Resolved",
"resource": "Resource",
"resource_approving_facility": "Resource approving facility",
Expand Down
115 changes: 115 additions & 0 deletions src/components/Auth/ForgotPasswordPanel.tsx

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prob don't need this component/can combine with ForgotPassword

Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import { useState } from "react";
import { useTranslation } from "react-i18next";

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

import CareIcon from "@/CAREUI/icons/CareIcon";

import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";

import { ForgotPasswordPhone } from "@/components/Auth/ForgotPasswordPhone";
import CircularProgress from "@/components/Common/CircularProgress";

type ForgotMethod = "email" | "phone";

interface ForgotPasswordPanelProps {
username: string;
usernameError?: string | null;
onUsernameChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
onSubmitEmail: (e: React.SubmitEvent<HTMLFormElement>) => void;
onBackToLogin: () => void;
isSubmitting: boolean;
}

export function ForgotPasswordPanel({
username,
usernameError,
onUsernameChange,
onSubmitEmail,
onBackToLogin,
isSubmitting,
}: ForgotPasswordPanelProps) {
const { t } = useTranslation();
const [forgotMethod, setForgotMethod] = useState<ForgotMethod>("email");

if (forgotMethod === "phone") {
return (
<ForgotPasswordPhone
onBackToEmail={() => setForgotMethod("email")}
onSuccess={onBackToLogin}
/>
);
}

return (
<form onSubmit={onSubmitEmail} className="space-y-4">
<Button
variant="link"
type="button"
onClick={onBackToLogin}
className="px-0 mb-4 flex items-center gap-2"
>
<CareIcon icon="l-arrow-left" className="text-lg" />
<span>{t("back_to_login")}</span>
</Button>

<div className="space-y-4">
<div>
<h2 className="text-2xl font-bold text-gray-900">
{t("forget_password")}
</h2>
<p className="text-sm text-gray-500 mt-2">
{t("forget_password_instruction")}
</p>
</div>

<div className="space-y-2">
<Label htmlFor="forgot_username">{t("username")}</Label>
<Input
id="forgot_username"
name="username"
type="text"
value={username}
onChange={onUsernameChange}
placeholder={t("enter_your_username")}
className={cn(
usernameError && "border-red-500 focus-visible:ring-red-500",
)}
/>
{usernameError && (
<p className="text-sm text-red-500">{t(usernameError)}</p>
)}
</div>

<Button
type="submit"
className="w-full"
variant="primary"
disabled={isSubmitting}
>
{isSubmitting ? (
<CircularProgress className="text-white" />
) : (
t("send_reset_link")
)}
</Button>

<div className="mt-5 text-center">
<p className="text-sm text-gray-500 font-base">
{t("cant_access_email")}
</p>
<Button
variant="link"
type="button"
onClick={() => setForgotMethod("phone")}
className="h-auto p-0 text-sm font-medium text-primary-500 hover:underline"
>
{t("reset_using_phone_number")}
</Button>
</div>
</div>
</form>
);
}
Loading
Loading