From 1f854087810503653e4f78e52ccb76eb2df19cf7 Mon Sep 17 00:00:00 2001 From: suprabathk Date: Tue, 5 Sep 2023 20:58:12 +0530 Subject: [PATCH 1/8] Using DateFormField instead of DateInputV2 --- .../Assets/AssetServiceEditModal.tsx | 26 ++++++++++++++----- src/Components/Facility/AssetCreate.tsx | 11 ++++---- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/Components/Assets/AssetServiceEditModal.tsx b/src/Components/Assets/AssetServiceEditModal.tsx index 75c9dd9fc60..e243c0c004d 100644 --- a/src/Components/Assets/AssetServiceEditModal.tsx +++ b/src/Components/Assets/AssetServiceEditModal.tsx @@ -7,10 +7,10 @@ import DialogModal from "../Common/Dialog"; import { AssetData, AssetService, AssetServiceEdit } from "./AssetTypes"; import dayjs from "dayjs"; import TextAreaFormField from "../Form/FormFields/TextAreaFormField"; -import DateInputV2 from "../Common/DateInputV2"; import { FieldLabel } from "../Form/FormFields/FormField"; import { formatDate, formatDateTime } from "../../Utils/utils"; import CareIcon from "../../CAREUI/icons/CareIcon"; +import DateFormField from "../Form/FormFields/DateFormField"; export const AssetServiceEditModal = (props: { asset?: AssetData; @@ -170,18 +170,30 @@ export const AssetServiceEditModal = (props: { data-testid="asset-last-serviced-on-input" > Serviced On - { - setForm({ - ...form, - serviced_on: dayjs(date).format("YYYY-MM-DD"), - }); + if ( + dayjs(date.value).format("YYYY-MM-DD") > + new Date( + props.service_record.created_date + ).toLocaleDateString("en-ca") + ) { + Notification.Error({ + msg: `Service date can't be after ${dayjs( + props.service_record.created_date + ).format("DD/MM/YYYY")} (Creation date)`, + }); + } else { + setForm({ + ...form, + serviced_on: dayjs(date.value).format("YYYY-MM-DD"), + }); + } }} - max={new Date(props.service_record.created_date)} /> diff --git a/src/Components/Facility/AssetCreate.tsx b/src/Components/Facility/AssetCreate.tsx index 1e6eead5242..7cdc5623da5 100644 --- a/src/Components/Facility/AssetCreate.tsx +++ b/src/Components/Facility/AssetCreate.tsx @@ -38,7 +38,7 @@ import useVisibility from "../../Utils/useVisibility"; import { validateEmailAddress } from "../../Common/validation"; import { dateQueryString } from "../../Utils/utils.js"; import dayjs from "../../Utils/dayjs"; -import DateInputV2 from "../Common/DateInputV2.js"; +import DateFormField from "../Form/FormFields/DateFormField.js"; const Loading = lazy(() => import("../Common/Loading")); @@ -876,24 +876,25 @@ const AssetCreate = (props: AssetProps) => { data-testid="asset-last-serviced-on-input" > Last Serviced On - { if ( - dayjs(date).format("YYYY-MM-DD") > + dayjs(date.value).format("YYYY-MM-DD") > new Date().toLocaleDateString("en-ca") ) { Notification.Error({ msg: "Last Serviced date can't be in future", }); } else { - setLastServicedOn(dayjs(date).format("YYYY-MM-DD")); + setLastServicedOn( + dayjs(date.value).format("YYYY-MM-DD") + ); } }} - max={new Date()} /> Date: Tue, 5 Sep 2023 21:26:27 +0530 Subject: [PATCH 2/8] Using Label from DateFormField --- src/Components/Assets/AssetServiceEditModal.tsx | 4 ++-- src/Components/Facility/AssetCreate.tsx | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Components/Assets/AssetServiceEditModal.tsx b/src/Components/Assets/AssetServiceEditModal.tsx index e243c0c004d..232cc5556b1 100644 --- a/src/Components/Assets/AssetServiceEditModal.tsx +++ b/src/Components/Assets/AssetServiceEditModal.tsx @@ -7,7 +7,6 @@ import DialogModal from "../Common/Dialog"; import { AssetData, AssetService, AssetServiceEdit } from "./AssetTypes"; import dayjs from "dayjs"; import TextAreaFormField from "../Form/FormFields/TextAreaFormField"; -import { FieldLabel } from "../Form/FormFields/FormField"; import { formatDate, formatDateTime } from "../../Utils/utils"; import CareIcon from "../../CAREUI/icons/CareIcon"; import DateFormField from "../Form/FormFields/DateFormField"; @@ -169,8 +168,9 @@ export const AssetServiceEditModal = (props: { className="col-span-6 sm:col-span-3" data-testid="asset-last-serviced-on-input" > - Serviced On { setSerialNumber(e.value)} @@ -875,8 +876,8 @@ const AssetCreate = (props: AssetProps) => { ref={fieldRef["last_serviced_on"]} data-testid="asset-last-serviced-on-input" > - Last Serviced On Date: Mon, 25 Sep 2023 12:46:47 +0530 Subject: [PATCH 3/8] Prevent Datepicker focus --- src/Components/Common/DateInputV2.tsx | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Components/Common/DateInputV2.tsx b/src/Components/Common/DateInputV2.tsx index bcebd4e0055..4549a0d99c6 100644 --- a/src/Components/Common/DateInputV2.tsx +++ b/src/Components/Common/DateInputV2.tsx @@ -252,10 +252,6 @@ const DateInputV2: React.FC = ({ { - popover.current?.focus(); - e.preventDefault(); - }} className="cui-input-base bg-gray-50" value={ displayValue.replace( From 888cbe6b131f349c9ce98cd28687764c693e7177 Mon Sep 17 00:00:00 2001 From: suprabathk Date: Mon, 25 Sep 2023 12:54:13 +0530 Subject: [PATCH 4/8] Removed unused Ref --- src/Components/Common/DateInputV2.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Components/Common/DateInputV2.tsx b/src/Components/Common/DateInputV2.tsx index 4549a0d99c6..7036d5c8bfb 100644 --- a/src/Components/Common/DateInputV2.tsx +++ b/src/Components/Common/DateInputV2.tsx @@ -1,4 +1,4 @@ -import { MutableRefObject, useEffect, useRef, useState } from "react"; +import { MutableRefObject, useEffect, useState } from "react"; import { addMonths, addYears, @@ -60,7 +60,6 @@ const DateInputV2: React.FC = ({ const [displayValue, setDisplayValue] = useState( value ? dayjs(value).format("DDMMYYYY") : "" ); - const popover = useRef(null); const decrement = () => { switch (type) { @@ -241,7 +240,6 @@ const DateInputV2: React.FC = ({ onBlur={() => { setIsOpen?.(false); }} - ref={popover} static className={classNames( "cui-dropdown-base absolute mt-0.5 w-72 divide-y-0 p-4", From 0580c470b33eda329dc3e117225fcd25f88c6a1c Mon Sep 17 00:00:00 2001 From: suprabathk Date: Mon, 25 Sep 2023 14:20:44 +0530 Subject: [PATCH 5/8] Using formatDate instead of .format --- src/Components/Assets/AssetServiceEditModal.tsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Components/Assets/AssetServiceEditModal.tsx b/src/Components/Assets/AssetServiceEditModal.tsx index 232cc5556b1..879007d1c8f 100644 --- a/src/Components/Assets/AssetServiceEditModal.tsx +++ b/src/Components/Assets/AssetServiceEditModal.tsx @@ -169,7 +169,6 @@ export const AssetServiceEditModal = (props: { data-testid="asset-last-serviced-on-input" > Date: Mon, 25 Sep 2023 14:54:40 +0530 Subject: [PATCH 6/8] Added translations --- .../Assets/AssetServiceEditModal.tsx | 33 +++++---- src/Components/Facility/AssetCreate.tsx | 71 ++++++++++--------- 2 files changed, 58 insertions(+), 46 deletions(-) diff --git a/src/Components/Assets/AssetServiceEditModal.tsx b/src/Components/Assets/AssetServiceEditModal.tsx index 879007d1c8f..a0fe4e81f74 100644 --- a/src/Components/Assets/AssetServiceEditModal.tsx +++ b/src/Components/Assets/AssetServiceEditModal.tsx @@ -10,6 +10,7 @@ import TextAreaFormField from "../Form/FormFields/TextAreaFormField"; import { formatDate, formatDateTime } from "../../Utils/utils"; import CareIcon from "../../CAREUI/icons/CareIcon"; import DateFormField from "../Form/FormFields/DateFormField"; +import { t } from "i18next"; export const AssetServiceEditModal = (props: { asset?: AssetData; @@ -60,12 +61,12 @@ export const AssetServiceEditModal = (props: {

- Update record for asset + {t("Update record for asset")} {props.asset?.name}

@@ -106,13 +107,17 @@ export const AssetServiceEditModal = (props: {
-

Edited On

+

+ {t("Edited On")} +

{formatDateTime(editRecord.edited_on)}

-

Edited By

+

+ {t("Edited By")} +

{editRecord.edited_by.username}

@@ -121,14 +126,16 @@ export const AssetServiceEditModal = (props: {

- Serviced On + {t("Serviced On")}

{formatDate(editRecord.serviced_on)}

-

Notes

+

+ {t("Notes")} +

{editRecord.note || "-"}

@@ -141,7 +148,7 @@ export const AssetServiceEditModal = (props: { editRecord ? setEditRecord(undefined) : props.handleClose(); }} > - {editRecord ? "Back" : "Close"} + {editRecord ? t("Back") : t("Close")}
@@ -153,12 +160,12 @@ export const AssetServiceEditModal = (props: {

- Update record for asset + {t("Update record for asset")} {props.asset?.name}

@@ -169,7 +176,7 @@ export const AssetServiceEditModal = (props: { data-testid="asset-last-serviced-on-input" > { setForm({ ...form, note: e.value }); @@ -212,7 +219,7 @@ export const AssetServiceEditModal = (props: {
diff --git a/src/Components/Facility/AssetCreate.tsx b/src/Components/Facility/AssetCreate.tsx index 810f0ffef6c..a81be6b1fc2 100644 --- a/src/Components/Facility/AssetCreate.tsx +++ b/src/Components/Facility/AssetCreate.tsx @@ -39,6 +39,7 @@ import { validateEmailAddress } from "../../Common/validation"; import { dateQueryString } from "../../Utils/utils.js"; import dayjs from "../../Utils/dayjs"; import DateFormField from "../Form/FormFields/DateFormField.js"; +import { t } from "i18next"; const Loading = lazy(() => import("../Common/Loading")); @@ -405,7 +406,7 @@ const AssetCreate = (props: AssetProps) => { if (locations.length === 0) { return ( {

- You need at least a location to create an assest. + {t("You need at least a location to create an assest.")}

@@ -441,7 +442,8 @@ const AssetCreate = (props: AssetProps) => { onClick={() => setIsScannerActive(false)} className="btn btn-default mb-2" > - Close Scanner + + {t("Close Scanner")} { } style={{ width: "100%" }} /> -

Scan Asset QR!

+

+ {t("Scan Asset QR!")} +

); @@ -480,7 +484,7 @@ const AssetCreate = (props: AssetProps) => { return (
{ > setName(value)} @@ -545,7 +549,7 @@ const AssetCreate = (props: AssetProps) => { {/* Location */} - Asset Location + {t("Asset Location")}
{ data-testid="asset-type-input" > { { > setDescription(value)} error={state.errors.description} @@ -665,7 +669,7 @@ const AssetCreate = (props: AssetProps) => { className="col-span-6" required name="is_working" - label="Working Status" + label={t("Working Status")} options={["true", "false"]} optionLabel={(option) => { return ( @@ -693,8 +697,8 @@ const AssetCreate = (props: AssetProps) => { > setNotWorkingReason(e.value)} error={state.errors.not_working_reason} @@ -718,7 +722,7 @@ const AssetCreate = (props: AssetProps) => { id="qr_code_id" name="qr_code_id" placeholder="" - label="Asset QR ID" + label={t("Asset QR ID")} value={qrCodeId} onChange={(e) => setQrCodeId(e.value)} error={state.errors.qr_code_id} @@ -744,9 +748,9 @@ const AssetCreate = (props: AssetProps) => { setManufacturer(e.value)} error={state.errors.manufacturer} /> @@ -761,7 +765,7 @@ const AssetCreate = (props: AssetProps) => { { const value = dayjs(event.value); @@ -789,8 +793,8 @@ const AssetCreate = (props: AssetProps) => { setSupportName(e.value)} error={state.errors.support_name} @@ -805,7 +809,7 @@ const AssetCreate = (props: AssetProps) => { > setSupportPhone(e.value)} @@ -823,8 +827,8 @@ const AssetCreate = (props: AssetProps) => { setSupportEmail(e.value)} error={state.errors.support_email} @@ -842,9 +846,9 @@ const AssetCreate = (props: AssetProps) => { setVendorName(e.value)} error={state.errors.vendor_name} /> @@ -859,8 +863,7 @@ const AssetCreate = (props: AssetProps) => { setSerialNumber(e.value)} error={state.errors.serial_number} @@ -877,7 +880,7 @@ const AssetCreate = (props: AssetProps) => { data-testid="asset-last-serviced-on-input" > { > setNotes(e.value)} error={state.errors.notes} @@ -931,13 +936,13 @@ const AssetCreate = (props: AssetProps) => { /> handleSubmit(e, false)} - label={assetId ? "Update" : "Create Asset"} + label={assetId ? t("Update") : t("Create Asset")} /> {!assetId && ( handleSubmit(e, true)} - label="Create & Add More" + label={t("Create & Add More")} /> )}
From 7c2575e4b8ebe5dde8b2a5d11fdc94daa8d726f3 Mon Sep 17 00:00:00 2001 From: suprabathk Date: Sun, 1 Oct 2023 11:54:34 +0530 Subject: [PATCH 7/8] Added translations for AssetServiceEditModal --- .../Assets/AssetServiceEditModal.tsx | 26 +++++++++---------- src/Locale/en/Asset.json | 14 +++++++++- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/Components/Assets/AssetServiceEditModal.tsx b/src/Components/Assets/AssetServiceEditModal.tsx index dfb2a51f51f..690524e471b 100644 --- a/src/Components/Assets/AssetServiceEditModal.tsx +++ b/src/Components/Assets/AssetServiceEditModal.tsx @@ -61,12 +61,12 @@ export const AssetServiceEditModal = (props: {

- {t("Update record for asset")} + {t("update_record_for_asset")} {props.asset?.name}

@@ -111,7 +111,7 @@ export const AssetServiceEditModal = (props: {

- {t("Edited On")} + {t("edited_on")}

{formatDateTime(editRecord.edited_on)} @@ -119,7 +119,7 @@ export const AssetServiceEditModal = (props: {

- {t("Edited By")} + {t("edited_by")}

{editRecord.edited_by.username} @@ -129,7 +129,7 @@ export const AssetServiceEditModal = (props: {

- {t("Serviced On")} + {t("serviced_on")}

- {t("Notes")} + {t("notes")}

{editRecord.note || "-"} @@ -157,7 +157,7 @@ export const AssetServiceEditModal = (props: { editRecord ? setEditRecord(undefined) : props.handleClose(); }} > - {editRecord ? t("Back") : t("Close")} + {editRecord ? t("back") : t("close")}

@@ -169,12 +169,12 @@ export const AssetServiceEditModal = (props: {

- {t("Update record for asset")} + {t("update_record_for_asset")} {props.asset?.name}

@@ -185,7 +185,7 @@ export const AssetServiceEditModal = (props: { data-testid="asset-last-serviced-on-input" > { setForm({ ...form, note: e.value }); @@ -228,7 +228,7 @@ export const AssetServiceEditModal = (props: {
diff --git a/src/Locale/en/Asset.json b/src/Locale/en/Asset.json index cf13de5cd47..f24549ee0b6 100644 --- a/src/Locale/en/Asset.json +++ b/src/Locale/en/Asset.json @@ -1,3 +1,15 @@ { - "create_asset": "Create Asset" + "create_asset": "Create Asset", + "edit_history": "Edit History", + "update_record_for_asset": "Update record for asset", + "edited_on": "Edited On", + "edited_by": "Edited By", + "serviced_on": "Serviced On", + "notes": "Notes", + "back": "Back", + "close": "Close", + "update_asset_service_record": "Update Asset Service Record", + "eg_details_on_functionality_service_etc": "Eg. Details on functionality, service, etc.", + "updating": "Updating", + "update": "Update" } From 9c562714db1a89d79f630a09f7bd30638ca9fd39 Mon Sep 17 00:00:00 2001 From: suprabathk Date: Sun, 1 Oct 2023 12:15:10 +0530 Subject: [PATCH 8/8] Added translations for AssetCreate --- src/Components/Facility/AssetCreate.tsx | 62 ++++++++++++------------- src/Locale/en/Facility.json | 34 +++++++++++++- 2 files changed, 64 insertions(+), 32 deletions(-) diff --git a/src/Components/Facility/AssetCreate.tsx b/src/Components/Facility/AssetCreate.tsx index a8093fe3bdb..beafe8d33c8 100644 --- a/src/Components/Facility/AssetCreate.tsx +++ b/src/Components/Facility/AssetCreate.tsx @@ -405,7 +405,7 @@ const AssetCreate = (props: AssetProps) => { if (locations.length === 0) { return ( {

- {t("You need at least a location to create an assest.")} + {t("you_need_at_least_a_location_to_create_an_assest")}

@@ -442,7 +442,7 @@ const AssetCreate = (props: AssetProps) => { className="btn btn-default mb-2" > - {t("Close Scanner")} + {t("close_scanner")} { style={{ width: "100%" }} />

- {t("Scan Asset QR!")} + {t("scan_asset_qr")}

); @@ -483,7 +483,7 @@ const AssetCreate = (props: AssetProps) => { return (
{ > setName(value)} @@ -548,7 +548,7 @@ const AssetCreate = (props: AssetProps) => { {/* Location */} - {t("Asset Location")} + {t("asset_location")}
{ data-testid="asset-type-input" > { { > setDescription(value)} error={state.errors.description} @@ -668,7 +668,7 @@ const AssetCreate = (props: AssetProps) => { className="col-span-6" required name="is_working" - label={t("Working Status")} + label={t("working_status")} options={["true", "false"]} optionLabel={(option) => { return ( @@ -696,8 +696,8 @@ const AssetCreate = (props: AssetProps) => { > setNotWorkingReason(e.value)} error={state.errors.not_working_reason} @@ -721,7 +721,7 @@ const AssetCreate = (props: AssetProps) => { id="qr_code_id" name="qr_code_id" placeholder="" - label={t("Asset QR ID")} + label={t("asset_qr_id")} value={qrCodeId} onChange={(e) => setQrCodeId(e.value)} error={state.errors.qr_code_id} @@ -747,9 +747,9 @@ const AssetCreate = (props: AssetProps) => { setManufacturer(e.value)} error={state.errors.manufacturer} /> @@ -764,7 +764,7 @@ const AssetCreate = (props: AssetProps) => { { const value = dayjs(event.value); @@ -792,8 +792,8 @@ const AssetCreate = (props: AssetProps) => { setSupportName(e.value)} error={state.errors.support_name} @@ -808,7 +808,7 @@ const AssetCreate = (props: AssetProps) => { > setSupportPhone(e.value)} @@ -826,8 +826,8 @@ const AssetCreate = (props: AssetProps) => { setSupportEmail(e.value)} error={state.errors.support_email} @@ -845,9 +845,9 @@ const AssetCreate = (props: AssetProps) => { setVendorName(e.value)} error={state.errors.vendor_name} /> @@ -862,7 +862,7 @@ const AssetCreate = (props: AssetProps) => { setSerialNumber(e.value)} error={state.errors.serial_number} @@ -879,7 +879,7 @@ const AssetCreate = (props: AssetProps) => { data-testid="asset-last-serviced-on-input" > { > { /> handleSubmit(e, false)} - label={assetId ? t("Update") : t("Create Asset")} + label={assetId ? t("update") : t("create_asset")} /> {!assetId && ( handleSubmit(e, true)} - label={t("Create & Add More")} + label={t("create_add_more")} /> )}
diff --git a/src/Locale/en/Facility.json b/src/Locale/en/Facility.json index aa44d86dda5..5e69f8108af 100644 --- a/src/Locale/en/Facility.json +++ b/src/Locale/en/Facility.json @@ -20,5 +20,37 @@ "type_b_cylinders": "B Type Cylinders", "type_c_cylinders": "C Type Cylinders", "type_d_cylinders": "D Type Cylinders", - "select_local_body": "Select Local Body" + "select_local_body": "Select Local Body", + "update_asset": "Update Asset", + "create_new_asset": "Create New Asset", + "you_need_at_least_a_location_to_create_an_assest": "You need at least a location to create an assest.", + "add_location": "Add Location", + "close_scanner": "Close Scanner", + "scan_asset_qr": "Scan Asset QR!", + "update": "Update", + "create": "Create", + "asset_name": "Asset Name", + "asset_location": "Asset Location", + "asset_type": "Asset Type", + "asset_class": "Asset Class", + "description": "Description", + "details_about_the_equipment": "Details about the equipment", + "working_status": "Working Status", + "why_the_asset_is_not_working": "Why the asset is not working?", + "describe_why_the_asset_is_not_working": "Describe why the asset is not working", + "asset_qr_id": "Asset QR ID", + "manufacturer": "Manufacturer", + "eg_xyz": "Eg. XYZ", + "eg_abc": "Eg. ABC", + "warranty_amc_expiry": "Warranty / AMC Expiry", + "customer_support_name": "Customer Support Name", + "customer_support_number": "Customer support number", + "customer_support_email": "Customer Support Email", + "eg_mail_example_com": "Eg. mail@example.com", + "vendor_name": "Vendor Name", + "serial_number": "Serial Number", + "last_serviced_on": "Last Serviced On", + "notes": "Notes", + "create_asset": "Create Asset", + "create_add_more": "Create & Add More" }