Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify CreateUserForm and add dirtyState to all react-hook-form #9749

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
5c43c3e
modify CreateUserForm and add dirtyState to all react-hook-form
rajku-dev Jan 4, 2025
dbe957c
Merge branch 'develop' into issue/9733/dirty-state
rajku-dev Jan 4, 2025
332ca54
fine dob field | drop destructuring
rajku-dev Jan 5, 2025
ec6e72e
use DatePicker instead
rajku-dev Jan 5, 2025
ad412ce
pass disable callback to date-picker
rajku-dev Jan 5, 2025
ababd0d
adjust disable logic
rajku-dev Jan 5, 2025
e924e69
handle api errors gracefully
rajku-dev Jan 5, 2025
3a7772e
fix negative age
rajku-dev Jan 6, 2025
33d899a
Merge branch 'develop' into issue/9733/dirty-state
rajku-dev Jan 6, 2025
e421cfc
Merge branch 'develop' into issue/9733/dirty-state
rajku-dev Jan 6, 2025
9d41d9d
fix `createEncounterForm` lint
rajku-dev Jan 6, 2025
804feff
Merge branch 'issue/9733/dirty-state' of https://github.com/rajku-dev…
rajku-dev Jan 6, 2025
4124583
use `useMutation` | add translations | refactor asterisk
rajku-dev Jan 7, 2025
5cf7fc3
use `toast` instead
rajku-dev Jan 7, 2025
0750df8
move schema out of component
rajku-dev Jan 7, 2025
88a4bce
Revert "move schema out of component"
rajku-dev Jan 7, 2025
642f7c1
extract precise API errors for fields
rajku-dev Jan 7, 2025
84dafdb
add translations for all field errors
rajku-dev Jan 7, 2025
3bb013c
reuse existing translations
rajku-dev Jan 7, 2025
42c1d58
switch to mutate
rajku-dev Jan 7, 2025
4299e3d
remove async
rajku-dev Jan 7, 2025
9382901
change TBody for UserApi.create route
rajku-dev Jan 7, 2025
9f9a10b
drop explicit type-safing
rajku-dev Jan 7, 2025
0908316
use relative imports
rajku-dev Jan 7, 2025
e73b85f
move new UserCreateRequest type to src/types/user
rajku-dev Jan 8, 2025
af44829
infer schema type directly
rajku-dev Jan 8, 2025
e134196
Merge branch 'develop' into issue/9733/dirty-state
rajku-dev Jan 8, 2025
add37a5
refactor `UserCreateRequest` type
rajku-dev Jan 8, 2025
fb1d00b
Merge branch 'issue/9733/dirty-state' of https://github.com/rajku-dev…
rajku-dev Jan 8, 2025
743c430
Merge branch 'develop' into issue/9733/dirty-state
rajku-dev Jan 8, 2025
5392459
edit schema | manually pick API payload fields from formValues
rajku-dev Jan 8, 2025
ad9b270
Merge branch 'develop' into issue/9733/dirty-state
rajku-dev Jan 8, 2025
aaa7d41
Revert "Merge branch 'develop' into issue/9733/dirty-state"
rajku-dev Jan 8, 2025
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
5 changes: 3 additions & 2 deletions crowdin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
files:
- source: public/locale/en.json
translation: /public/locale/%two_letters_code%.json
- source: /public/locale/{{lang}}.json
translation: /public/locale/%two_letters_code%/%original_file_name%
bundles:
- 2

14 changes: 8 additions & 6 deletions public/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,6 @@
"all_changes_have_been_saved": "All changes have been saved",
"all_details": "All Details",
"all_patients": "All Patients",
"allergen": "Allergen",
"allergies": "Allergies",
"allow_transfer": "Allow Transfer",
"allowed_formats_are": "Allowed formats are",
Expand Down Expand Up @@ -651,7 +650,6 @@
"created_by": "Created By",
"created_date": "Created Date",
"created_on": "Created On",
"criticality": "Criticality",
"csv_file_in_the_specified_format": "Select a CSV file in the specified format",
"current_address": "Current Address",
"current_password": "Current Password",
Expand All @@ -669,6 +667,7 @@
"date_of_admission": "Date of Admission",
"date_of_birth": "Date of Birth",
"date_of_birth_age": "Date of Birth/Age",
"date_of_birth_cannot_be_in_future": "Date of birth cannot be in the future",
"date_of_birth_or_age": "Date of Birth or Age",
"date_of_positive_covid_19_swab": "Date of Positive Covid 19 Swab",
"date_of_result": "Covid confirmation date",
Expand Down Expand Up @@ -831,7 +830,6 @@
"encounter_discharge_disposition__snf": "Skilled nursing facility",
"encounter_duration_confirmation": "The duration of this encounter would be",
"encounter_id": "Encounter ID",
"encounter_marked_as_complete": "Encounter Completed",
"encounter_notes__all_discussions": "All Discussions",
"encounter_notes__be_first_to_send": "Be the first to send a message",
"encounter_notes__choose_template": "Choose a template or enter a custom title",
Expand Down Expand Up @@ -902,7 +900,6 @@
"error_deleting_shifting": "Error while deleting Shifting record",
"error_fetching_slots_data": "Error while fetching slots data",
"error_sending_otp": "Error while sending OTP, Please try again later",
"error_updating_encounter": "Error to Updating Encounter",
"error_verifying_otp": "Error while verifying OTP, Please request a new OTP",
"error_while_deleting_record": "Error while deleting record",
"escape": "Escape",
Expand Down Expand Up @@ -1167,7 +1164,6 @@
"manufacturer": "Manufacturer",
"map_acronym": "M.A.P.",
"mark_all_as_read": "Mark all as Read",
"mark_as_complete": "Mark as Complete",
"mark_as_fulfilled": "Mark as Fullfilled",
"mark_as_noshow": "Mark as no-show",
"mark_as_read": "Mark as Read",
Expand Down Expand Up @@ -1416,6 +1412,7 @@
"phone_number": "Phone Number",
"phone_number_at_current_facility": "Phone Number of Contact person at current Facility",
"phone_number_min_error": "Phone number must be at least 10 characters long",
"phone_number_must_start": "Phone number must start with +91 followed by 10 digits",
"phone_number_verified": "Phone Number Verified",
"pincode": "Pincode",
"pincode_autofill": "State and District auto-filled from Pincode",
Expand Down Expand Up @@ -1632,7 +1629,6 @@
"select": "Select",
"select_all": "Select All",
"select_date": "Select date",
"select_department": "Select Department",
"select_eligible_policy": "Select an Eligible Insurance Policy",
"select_facility_for_discharged_patients_warning": "Facility needs to be selected to view discharged patients.",
"select_for_administration": "Select for Administration",
Expand Down Expand Up @@ -1743,6 +1739,7 @@
"thank_you_for_choosing": "Thank you for choosing our care service",
"the_request_for_resources_placed_by_yourself_is": "The request for resource (details below) placed by yourself is",
"third_party_software_licenses": "Third Party Software Licenses",
"this_field_is_required": "This field is required",
"time": "Time",
"time_slot": "Time Slot",
"title_of_request": "Title of Request",
Expand Down Expand Up @@ -1862,7 +1859,12 @@
"username": "Username",
"username_already_exists": "This username already exists",
"username_available": "Username is available",
"username_consecutive_special_characters": "Username can't contain consecutive special characters",
"username_contain_lowercase_special": "Username can only contain lowercase letters, numbers, and . _ -",
"username_less_than": "Username must be less than 16 characters",
"username_more_than": "Username must be at least 4 characters",
"username_not_available": "Username is not available",
"username_start_end_letter_number": "Username must start and end with a letter or number",
"username_userdetails_not_found": "Unable to fetch details as username or user details not found",
"users": "Users",
"vacant": "Vacant",
Expand Down
48 changes: 24 additions & 24 deletions src/Routers/routes/ConsultationRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,26 @@ const consultationRoutes: AppRoutes = {
patientId={patientId}
/>
),
"/facility/:facilityId/patient/:patientId/consultation/:id/consent-records":
({ facilityId, patientId, id }) => (
<PatientConsentRecords
facilityId={facilityId}
patientId={patientId}
consultationId={id}
/>
),
"/facility/:facilityId/patient/:patientId/encounterId/:id/files/": ({
facilityId,
patientId,
id,
}) => (
<FileUploadPage
facilityId={facilityId}
patientId={patientId}
encounterId={id}
type="encounter"
/>
),
"/facility/:facilityId/patient/:patientId/questionnaire": ({
facilityId,
patientId,
Expand All @@ -60,6 +80,10 @@ const consultationRoutes: AppRoutes = {
patientId={patientId}
/>
),
"/facility/:facilityId/patient/:patientId/encounter/:encounterId/questionnaire_response/:id":
({ patientId, id }) => (
<QuestionnaireResponseView responseId={id} patientId={patientId} />
),
"/facility/:facilityId/patient/:patientId/encounter/:encounterId/questionnaire/:slug":
({ facilityId, encounterId, slug, patientId }) => (
<EncounterQuestionnaire
Expand All @@ -69,30 +93,6 @@ const consultationRoutes: AppRoutes = {
patientId={patientId}
/>
),
"/facility/:facilityId/patient/:patientId/encounter/:encounterId/questionnaire_response/:id":
({ patientId, id }) => (
<QuestionnaireResponseView responseId={id} patientId={patientId} />
),
"/facility/:facilityId/patient/:patientId/consultation/:id/consent-records":
({ facilityId, patientId, id }) => (
<PatientConsentRecords
facilityId={facilityId}
patientId={patientId}
consultationId={id}
/>
),
"/facility/:facilityId/patient/:patientId/encounterId/:id/files/": ({
facilityId,
patientId,
id,
}) => (
<FileUploadPage
facilityId={facilityId}
patientId={patientId}
encounterId={id}
type="encounter"
/>
),
};

export default consultationRoutes;
7 changes: 5 additions & 2 deletions src/components/Encounter/CreateEncounterForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,11 @@ export default function CreateEncounterForm({
form.setValue("organizations", [value]);
}}
/>

<Button type="submit" className="w-full" disabled={isPending}>
<Button
type="submit"
className="w-full"
disabled={isPending || !form.formState.isDirty}
>
{isPending ? "Creating..." : "Create Encounter"}
</Button>
</form>
Expand Down
6 changes: 5 additions & 1 deletion src/components/Facility/FacilityCreate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,11 @@ export const FacilityCreate = (props: FacilityProps) => {
>
{t("cancel")}
</Button>
<Button variant="primary" type="submit" disabled={isLoading}>
<Button
variant="primary"
type="submit"
disabled={isLoading || !form.formState.isDirty}
>
{isLoading ? (
<Loading />
) : facilityId ? (
Expand Down
91 changes: 8 additions & 83 deletions src/components/Patient/PatientInfoCard.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useMutation, useQueryClient } from "@tanstack/react-query";
import {
BedSingle,
Building,
Expand All @@ -10,18 +9,8 @@ import {
} from "lucide-react";
import { Link } from "raviger";
import { useTranslation } from "react-i18next";
import { toast } from "sonner";

import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
import {
Popover,
PopoverContent,
Expand All @@ -30,29 +19,13 @@ import {

import { Avatar } from "@/components/Common/Avatar";

import routes from "@/Utils/request/api";
import mutate from "@/Utils/request/mutate";
import { formatDateTime, formatPatientAge } from "@/Utils/utils";
import { Encounter, completedEncounterStatus } from "@/types/emr/encounter";
import { Patient } from "@/types/emr/newPatient";

import { Button } from "../ui/button";
import ManageEncounterOrganizations from "./ManageEncounterOrganizations";

const QUESTIONNAIRE_OPTIONS = [
{
slug: "encounter",
title: "Update Encounter",
},
{
slug: "community-nurse",
title: "Community Nurse Form",
},
{
slug: "recommend_discharge_v2",
title: "Recommend Discharge",
},
] as const;

export interface PatientInfoCardProps {
patient: Patient;
encounter: Encounter;
Expand All @@ -62,36 +35,6 @@ export interface PatientInfoCardProps {
export default function PatientInfoCard(props: PatientInfoCardProps) {
const { patient, encounter } = props;
const { t } = useTranslation();
const queryClient = useQueryClient();

const { mutate: updateEncounter } = useMutation({
mutationFn: mutate(routes.encounter.update, {
pathParams: { id: encounter.id },
}),
onSuccess: () => {
toast.success(t("encounter_marked_as_complete"));
queryClient.invalidateQueries({ queryKey: ["encounter", encounter.id] });
},
onError: () => {
toast.error(t("error_updating_encounter"));
},
});

const handleMarkAsComplete = () => {
updateEncounter({
...encounter,
status: "completed",
organizations: encounter.organizations.map((org) => org.id),
patient: encounter.patient.id,
encounter_class: encounter.encounter_class,
period: encounter.period,
hospitalization: encounter.hospitalization,
priority: encounter.priority,
external_identifier: encounter.external_identifier,
facility: encounter.facility.id,
});
};

return (
<>
<section className="flex flex-col lg:flex-row">
Expand Down Expand Up @@ -319,31 +262,13 @@ export default function PatientInfoCard(props: PatientInfoCardProps) {
>
{!completedEncounterStatus.includes(encounter.status) && (
<div className="flex w-full flex-col gap-3 lg:w-auto 2xl:flex-row">
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="primary">
{t("update")}
<ChevronDown className="ml-2 h-4 w-4" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
{QUESTIONNAIRE_OPTIONS.map((option) => (
<DropdownMenuItem key={option.slug} asChild>
<Link
href={`/facility/${encounter.facility.id}/patient/${patient.id}/encounter/${encounter.id}/questionnaire/${option.slug}`}
className="cursor-pointer text-gray-800"
>
{t(option.title)}
</Link>
</DropdownMenuItem>
))}
<DropdownMenuSeparator />
<DropdownMenuLabel>{t("actions")}</DropdownMenuLabel>
<DropdownMenuItem onClick={handleMarkAsComplete}>
{t("mark_as_complete")}
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
<Button asChild variant="primary">
<Link
href={`/facility/${encounter.facility.id}/patient/${patient.id}/encounter/${encounter.id}/edit_encounter`}
>
Update Encounter
</Link>
</Button>
</div>
)}
</div>
Expand Down
Loading
Loading