-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The 'Add OTP token' option creates a new OTP token associated to a specific user. The QR code has been generated using the qrcode.react[1] library. [1]- https://github.com/zpao/qrcode.react Signed-off-by: Carla Martinez <carlmart@redhat.com>
- Loading branch information
Showing
7 changed files
with
891 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import React from "react"; | ||
// PatternFly | ||
import { | ||
DatePicker, | ||
InputGroup, | ||
TimePicker, | ||
isValidDate, | ||
yyyyMMddFormat, | ||
} from "@patternfly/react-core"; | ||
// Utils | ||
import { | ||
parseFullDateStringToUTCFormat, | ||
toGeneralizedTime, | ||
} from "src/utils/utils"; | ||
|
||
interface PropsToDateTimeSelector { | ||
timeValue: string; // Generalized time format ('YYYYMMDDHHMMSSZ') | ||
setTimeValue: (timeValue: string) => void; | ||
name: string; | ||
ariaLabel?: string; | ||
isDisabled?: boolean; | ||
} | ||
|
||
const DateTimeSelector = (props: PropsToDateTimeSelector) => { | ||
const [valueDate, setValueDate] = React.useState<Date | null>(null); | ||
|
||
// Parse the current date into 'Date' format | ||
React.useEffect(() => { | ||
if (props.timeValue) { | ||
const date = parseFullDateStringToUTCFormat(props.timeValue); | ||
setValueDate(date); | ||
} | ||
}, [props.timeValue]); | ||
|
||
// On change date handler | ||
const onDateChange = ( | ||
_event: React.FormEvent<HTMLInputElement>, | ||
inputDate: string, | ||
newFromDate: Date | undefined | ||
) => { | ||
if (newFromDate !== undefined) { | ||
if ( | ||
valueDate && | ||
isValidDate(valueDate) && | ||
isValidDate(newFromDate) && | ||
inputDate === yyyyMMddFormat(newFromDate) | ||
) { | ||
newFromDate.setHours(valueDate.getHours()); | ||
newFromDate.setMinutes(valueDate.getMinutes()); | ||
} | ||
if ( | ||
isValidDate(newFromDate) && | ||
inputDate === yyyyMMddFormat(newFromDate) | ||
) { | ||
setValueDate(newFromDate); | ||
// Parse to generalized format | ||
props.setTimeValue(toGeneralizedTime(newFromDate)); | ||
} | ||
} | ||
}; | ||
|
||
// On change time handler | ||
const onTimeChange = (_event, time, hour, minute) => { | ||
let updatedFromDate = new Date(); | ||
if (valueDate && isValidDate(valueDate)) { | ||
updatedFromDate = valueDate; | ||
} | ||
updatedFromDate.setHours(hour); | ||
updatedFromDate.setMinutes(minute); | ||
|
||
setValueDate(updatedFromDate); | ||
// Parse to generalized format | ||
props.setTimeValue(toGeneralizedTime(updatedFromDate)); | ||
}; | ||
|
||
// Parse the current date into 'HH:MM' format | ||
const hhMMFormat = (date: Date) => { | ||
const hours = date.getHours().toString().padStart(2, "0"); | ||
const minutes = date.getMinutes().toString().padStart(2, "0"); | ||
|
||
return hours + ":" + minutes; | ||
}; | ||
|
||
return ( | ||
<InputGroup> | ||
<DatePicker | ||
name={props.name} | ||
value={valueDate !== null ? yyyyMMddFormat(valueDate) : ""} | ||
onChange={onDateChange} | ||
aria-label={props.ariaLabel || props.name} | ||
placeholder="YYYY-MM-DD" | ||
isDisabled={props.isDisabled || false} | ||
/> | ||
<TimePicker | ||
name={props.name} | ||
time={valueDate !== null ? hhMMFormat(valueDate) : ""} | ||
aria-label={props.ariaLabel || props.name} | ||
onChange={onTimeChange} | ||
placeholder="HH:MM" | ||
is24Hour={true} | ||
isDisabled={props.isDisabled || false} | ||
/> | ||
</InputGroup> | ||
); | ||
}; | ||
|
||
export default DateTimeSelector; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React from "react"; | ||
// PatternFly | ||
import { HelperText, HelperTextItem } from "@patternfly/react-core"; | ||
// Icons | ||
import { | ||
InfoIcon, | ||
QuestionIcon, | ||
ExclamationIcon, | ||
CheckIcon, | ||
TimesIcon, | ||
} from "@patternfly/react-icons"; | ||
|
||
type IconType = "info" | "question" | "warning" | "success" | "error"; | ||
|
||
interface PropsToHelperTextWithIcon { | ||
message: string | React.ReactNode; | ||
type?: IconType; | ||
} | ||
|
||
const getIcon = (type?: IconType) => { | ||
switch (type) { | ||
case "info": | ||
return <InfoIcon />; | ||
case "question": | ||
return <QuestionIcon />; | ||
case "warning": | ||
return <ExclamationIcon />; | ||
case "success": | ||
return <CheckIcon />; | ||
case "error": | ||
return <TimesIcon />; | ||
default: | ||
return <InfoIcon />; | ||
} | ||
}; | ||
|
||
const HelperTextWithIcon = (props: PropsToHelperTextWithIcon) => { | ||
return ( | ||
<HelperText> | ||
{!props.type ? ( | ||
<HelperTextItem>{props.message}</HelperTextItem> | ||
) : ( | ||
<HelperTextItem icon={getIcon(props.type)}> | ||
{props.message} | ||
</HelperTextItem> | ||
)} | ||
</HelperText> | ||
); | ||
}; | ||
|
||
export default HelperTextWithIcon; |
Oops, something went wrong.