Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
shivankacker committed Oct 25, 2024
1 parent 2f9bd97 commit 880447e
Show file tree
Hide file tree
Showing 23 changed files with 29 additions and 87 deletions.
17 changes: 0 additions & 17 deletions package-lock.json

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

1 change: 0 additions & 1 deletion src/components/ABDM/FetchRecordsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ export default function FetchRecordsModal({ abha, show, onClose }: IProps) {
label={t("consent_request__expiry")}
required
disablePast
position="TOP-RIGHT"
/>

<div className="mt-6 flex items-center justify-end">
Expand Down
1 change: 0 additions & 1 deletion src/components/Assets/AssetServiceEditModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ export const AssetServiceEditModal = (props: {
label={t("serviced_on")}
name="serviced_on"
className="mt-2"
position="LEFT"
value={new Date(form.serviced_on)}
max={new Date(props.service_record.created_date)}
onChange={(date) => {
Expand Down
28 changes: 9 additions & 19 deletions src/components/Common/DateInputV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,6 @@ import { t } from "i18next";
import DateTextInput from "./DateTextInput";

type DatePickerType = "date" | "month" | "year";
export type DatePickerPosition =
| "LEFT"
| "RIGHT"
| "CENTER"
| "LEFT-CENTER"
| "RIGHT-CENTER"
| "TOP-LEFT"
| "TOP-RIGHT"
| "TOP-CENTER";

interface Props {
id?: string;
Expand All @@ -29,12 +20,11 @@ interface Props {
max?: Date;
outOfLimitsErrorMessage?: string;
onChange: (date: Date | undefined) => void;
position?: DatePickerPosition;
disabled?: boolean;
placeholder?: string;
isOpen?: boolean;
setIsOpen?: (isOpen: boolean) => void;
time?: boolean;
allowTime?: boolean;
popOverClassName?: string;
}

Expand All @@ -53,7 +43,7 @@ const DateInputV2: React.FC<Props> = ({
disabled,
placeholder,
setIsOpen,
time,
allowTime,
isOpen,
popOverClassName,
}) => {
Expand Down Expand Up @@ -84,7 +74,7 @@ const DateInputV2: React.FC<Props> = ({
};

const handleChange = (date: Date) => {
onChange(time ? date : getDayStart(date));
onChange(allowTime ? date : getDayStart(date));
};

const decrement = () => {
Expand Down Expand Up @@ -140,7 +130,7 @@ const DateInputV2: React.FC<Props> = ({
datePickerHeaderDate.getSeconds(),
),
);
if (!time) {
if (!allowTime) {
close();
setIsOpen?.(false);
}
Expand Down Expand Up @@ -276,7 +266,7 @@ const DateInputV2: React.FC<Props> = ({
isOpen && popoverButtonRef.current?.click();
}, [isOpen]);

const dateFormat = `DD/MM/YYYY${time ? " hh:mm a" : ""}`;
const dateFormat = `DD/MM/YYYY${allowTime ? " hh:mm a" : ""}`;

const getPosition = () => {
const viewportWidth = document.documentElement.clientWidth;
Expand All @@ -285,7 +275,7 @@ const DateInputV2: React.FC<Props> = ({
const popOverX = popoverButtonRef.current?.getBoundingClientRect().x || 0;
const popOverY = popoverButtonRef.current?.getBoundingClientRect().y || 0;

const right = popOverX > viewportWidth - (time ? 420 : 300);
const right = popOverX > viewportWidth - (allowTime ? 420 : 300);
const top = popOverY > viewportHeight - 400;

return `${right ? "md:-translate-x-1/2" : ""} ${top ? "md:-translate-y-[calc(100%+50px)]" : ""}`;
Expand Down Expand Up @@ -327,7 +317,7 @@ const DateInputV2: React.FC<Props> = ({
{open && (
<PopoverPanel
className={classNames(
`cui-dropdown-base absolute my-0.5 ${time ? "max-h-[80vh] w-full md:h-auto md:w-[400px]" : "w-72"} divide-y-0 rounded p-4`,
`cui-dropdown-base absolute my-0.5 ${allowTime ? "max-h-[80vh] w-full md:h-auto md:w-[400px]" : "w-72"} divide-y-0 rounded p-4`,
getPosition(),
popOverClassName,
)}
Expand All @@ -338,7 +328,7 @@ const DateInputV2: React.FC<Props> = ({
)}
>
<DateTextInput
allowTime={!!time}
allowTime={!!allowTime}
value={value}
onChange={onChange}
onFinishInitialTyping={() => close()}
Expand Down Expand Up @@ -537,7 +527,7 @@ const DateInputV2: React.FC<Props> = ({
</div>
)}
</div>
{time && (
{allowTime && (
<div className="flex shrink-0 gap-1">
{(
[
Expand Down
8 changes: 3 additions & 5 deletions src/components/Common/DateRangeInputV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type Props = {
disabled?: boolean;
max?: Date;
min?: Date;
time?: boolean;
allowTime?: boolean;
};

const DateRangeInputV2 = ({ value, onChange, ...props }: Props) => {
Expand All @@ -34,10 +34,9 @@ const DateRangeInputV2 = ({ value, onChange, ...props }: Props) => {
}}
min={props.min}
max={end || props.max}
position="RIGHT-CENTER"
placeholder="Start date"
disabled={props.disabled}
time={props.time}
allowTime={props.allowTime}
/>
</div>
<div className="flex-auto">
Expand All @@ -48,12 +47,11 @@ const DateRangeInputV2 = ({ value, onChange, ...props }: Props) => {
onChange={(end) => onChange({ start, end })}
min={start || props.min}
max={props.max}
position="CENTER"
disabled={props.disabled || !start}
placeholder="End date"
isOpen={showEndPicker}
setIsOpen={setShowEndPicker}
time={props.time}
allowTime={props.allowTime}
/>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export default function InvestigationBuilder(
i,
)
}
time
allowTime
errorClassName="hidden"
className="w-full"
onFocus={() => setActiveIdx(i)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export default function ProcedureBuilder(props: Props<ProcedureType>) {
i,
)
}
time
allowTime
errorClassName="hidden"
className="w-full"
onFocus={() => setActiveIdx(i)}
Expand Down
6 changes: 0 additions & 6 deletions src/components/DeathReport/DeathReport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,6 @@ export default function PrintDeathReport(props: { id: string }) {
<DateFormField
{...field("date_declared_positive")}
label={t("date_declared_positive")}
position="LEFT"
className="w-full"
disableFuture
/>
Expand All @@ -428,14 +427,12 @@ export default function PrintDeathReport(props: { id: string }) {
<DateFormField
{...field("date_of_test")}
label={t("date_of_test")}
position="LEFT"
/>
</div>
<div>
<DateFormField
{...field("date_of_result")}
label={t("date_of_result")}
position="LEFT"
disableFuture
/>
</div>
Expand Down Expand Up @@ -477,15 +474,13 @@ export default function PrintDeathReport(props: { id: string }) {
<DateFormField
{...field("date_of_admission")}
label="Date of admission"
position="LEFT"
disableFuture
/>
</div>
<div>
<DateFormField
{...field("date_of_death")}
label="Date of death"
position="LEFT"
disableFuture
/>
</div>
Expand Down Expand Up @@ -534,7 +529,6 @@ export default function PrintDeathReport(props: { id: string }) {
<DateFormField
{...field("kottayam_sample_date")}
label="Sample sent to NIV/IUCBR Kottayam on"
position="LEFT"
/>
</div>
</div>
Expand Down
1 change: 0 additions & 1 deletion src/components/Facility/AssetCreate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,6 @@ const AssetCreate = (props: AssetProps) => {
label={t("last_serviced_on")}
name="last_serviced_on"
className="mt-2"
position="TOP-RIGHT"
disableFuture
value={last_serviced_on && new Date(last_serviced_on)}
onChange={(date) => {
Expand Down
6 changes: 3 additions & 3 deletions src/components/Facility/ConsultationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1195,7 +1195,7 @@ export const ConsultationForm = ({ facilityId, patientId, id }: Props) => {
value: dayjs(e.value).format("YYYY-MM-DDTHH:mm"),
})
}
time
allowTime
errorClassName="hidden"
/>
</div>
Expand Down Expand Up @@ -1242,7 +1242,7 @@ export const ConsultationForm = ({ facilityId, patientId, id }: Props) => {
value: dayjs(e.value).format("YYYY-MM-DDTHH:mm"),
})
}
time
allowTime
errorClassName="hidden"
/>
{dayjs().diff(state.form.encounter_date, "day") > 30 && (
Expand Down Expand Up @@ -1281,7 +1281,7 @@ export const ConsultationForm = ({ facilityId, patientId, id }: Props) => {
value: dayjs(e.value).format("YYYY-MM-DDTHH:mm"),
})
}
time
allowTime
errorClassName="hidden"
/>
</div>
Expand Down
3 changes: 1 addition & 2 deletions src/components/Facility/Consultations/Beds.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,7 @@ const Beds = (props: BedsProps) => {
max={new Date()}
error=""
errorClassName="hidden"
position="TOP-RIGHT"
time
allowTime
/>
<div>
<FieldLabel id="assets-link-label">Link Assets</FieldLabel>
Expand Down
4 changes: 2 additions & 2 deletions src/components/Facility/Consultations/DailyRoundsFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export default function DailyRoundsFilter(props: Props) {
}
max={new Date()}
errorClassName="hidden"
time
allowTime
/>
<DateFormField
{...field("taken_at_before")}
Expand All @@ -113,7 +113,7 @@ export default function DailyRoundsFilter(props: Props) {
}
max={new Date()}
errorClassName="hidden"
time
allowTime
/>
<PopoverButton>
<ButtonV2
Expand Down
3 changes: 1 addition & 2 deletions src/components/Facility/DischargeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,6 @@ const DischargeModal = ({
value={
dischargeOrDeathTime ? new Date(dischargeOrDeathTime) : new Date()
}
position="TOP-RIGHT"
popOverClassName="max-h-[50vh]"
onChange={(e) => {
const updates: Record<string, string | undefined> = {
Expand All @@ -340,7 +339,7 @@ const DischargeModal = ({
? errors?.death_datetime
: errors?.discharge_date
}
time
allowTime
/>

{discharge_reason !==
Expand Down
1 change: 0 additions & 1 deletion src/components/Facility/TriageForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ export const TriageForm = ({ facilityId, id }: Props) => {
value={state.form.entry_date}
disableFuture
onChange={handleFormFieldChange}
position="LEFT"
placeholder="Entry Date"
error={state.errors.entry_date}
/>
Expand Down
10 changes: 3 additions & 7 deletions src/components/Form/FormFields/DateFormField.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import DateInputV2, {
DatePickerPosition,
} from "@/components/Common/DateInputV2";
import DateInputV2 from "@/components/Common/DateInputV2";
import { FormFieldBaseProps, useFormFieldPropsResolver } from "./Utils";

import FormField from "./FormField";
Expand All @@ -11,10 +9,9 @@ type Props = FormFieldBaseProps<Date> & {
placeholder?: string;
max?: Date;
min?: Date;
position?: DatePickerPosition;
disableFuture?: boolean;
disablePast?: boolean;
time?: boolean;
allowTime?: boolean;
popOverClassName?: string;
};

Expand Down Expand Up @@ -50,9 +47,8 @@ const DateFormField = (props: Props) => {
disabled={field.disabled}
max={props.max ?? (props.disableFuture ? new Date() : undefined)}
min={props.min ?? (props.disablePast ? yesterday() : undefined)}
position={props.position ?? "RIGHT"}
placeholder={props.placeholder}
time={props.time}
allowTime={props.allowTime}
popOverClassName={props.popOverClassName}
/>
</FormField>
Expand Down
4 changes: 2 additions & 2 deletions src/components/Form/FormFields/DateRangeFormField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type Props = FormFieldBaseProps<DateRange> & {
min?: Date;
disableFuture?: boolean;
disablePast?: boolean;
time?: boolean;
allowTime?: boolean;
};

/**
Expand Down Expand Up @@ -40,7 +40,7 @@ const DateRangeFormField = (props: Props) => {
disabled={field.disabled}
min={props.min || (props.disableFuture ? new Date() : undefined)}
max={props.max || (props.disablePast ? new Date() : undefined)}
time={props.time}
allowTime={props.allowTime}
/>
</FormField>
);
Expand Down
3 changes: 1 addition & 2 deletions src/components/Medicine/AdministerMedicine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ export default function AdministerMedicine({ prescription, ...props }: Props) {
min={new Date(prescription.created_date)}
max={new Date()}
errorClassName="hidden"
position="TOP-RIGHT"
time
allowTime
/>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Medicine/MedicineAdministration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export default function MedicineAdministration(props: Props) {
max={new Date()}
className="w-full"
errorClassName="hidden"
time
allowTime
/>
</div>
</div>
Expand Down
Loading

0 comments on commit 880447e

Please sign in to comment.