From ba72e709808f4d1443b6351225da3422db4e91c2 Mon Sep 17 00:00:00 2001 From: Anzhela Date: Tue, 17 Sep 2024 15:48:51 +0400 Subject: [PATCH 1/2] fix: fixed placeholder for AM/PM --- src/Body/Fields/Time/Time.js | 12 ++++++++---- src/Helpers/time.js | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Body/Fields/Time/Time.js b/src/Body/Fields/Time/Time.js index c35bb6d8..1987a398 100644 --- a/src/Body/Fields/Time/Time.js +++ b/src/Body/Fields/Time/Time.js @@ -1,4 +1,4 @@ -import React, { Fragment } from 'react' +import React, { Fragment, useEffect, useState } from 'react' import { Input, Select } from 'boomform' import { getTimeFields } from './../../../Helpers/time' import { getInitial, getValidation } from './../../../Helpers/global' @@ -15,9 +15,13 @@ const Time = ({ payment, ...props }) => { + const [amPm, setAmPm] = useState(placeholders.format) + useEffect(() => { + setAmPm(placeholders.format) + }, [placeholders.format]) return ( <> - {getTimeFields(format, placeholders).map((item) => { + {getTimeFields(format, placeholders).map(item => { const { key, placeholder } = item return ( @@ -43,8 +47,8 @@ const Time = ({ id={`${id}.${key}`} initial={initials?.format || 1} options={[ - { key: 1, value: 'AM' }, - { key: 2, value: 'PM' } + { key: 1, value: amPm }, + { key: 2, value: amPm === 'AM' ? 'PM' : 'AM' } ]} /> )} diff --git a/src/Helpers/time.js b/src/Helpers/time.js index e5a300ec..cab9c353 100644 --- a/src/Helpers/time.js +++ b/src/Helpers/time.js @@ -2,7 +2,7 @@ export const getTimeFields = (format, placeholders) => { const fields = [ { key: 'hour', placeholder: placeholders?.hour || 'HH' }, { key: 'minute', placeholder: placeholders?.minute || 'MM' }, - { key: 'format' } + { key: 'format', placeholder: placeholders?.format || 'AM/PM' } ] return format === '24h' ? fields.splice(0, 2) : fields } From 458fc30f012a1d2ebe0fd68132c58fede917336c Mon Sep 17 00:00:00 2001 From: Anzhela Date: Wed, 18 Sep 2024 12:16:11 +0400 Subject: [PATCH 2/2] fix: removed extra format, fixed initial value --- src/Body/Fields/Time/Time.js | 12 ++++-------- src/Helpers/time.js | 2 +- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/Body/Fields/Time/Time.js b/src/Body/Fields/Time/Time.js index 1987a398..8af86d36 100644 --- a/src/Body/Fields/Time/Time.js +++ b/src/Body/Fields/Time/Time.js @@ -1,4 +1,4 @@ -import React, { Fragment, useEffect, useState } from 'react' +import React, { Fragment } from 'react' import { Input, Select } from 'boomform' import { getTimeFields } from './../../../Helpers/time' import { getInitial, getValidation } from './../../../Helpers/global' @@ -15,10 +15,6 @@ const Time = ({ payment, ...props }) => { - const [amPm, setAmPm] = useState(placeholders.format) - useEffect(() => { - setAmPm(placeholders.format) - }, [placeholders.format]) return ( <> {getTimeFields(format, placeholders).map(item => { @@ -45,10 +41,10 @@ const Time = ({