|
1 | 1 | import { makeStyles } from "@material-ui/core/styles"
|
| 2 | +import TextField from "@material-ui/core/TextField" |
| 3 | +import { ChooseOne, Cond } from "components/Conditionals/ChooseOne" |
| 4 | +import { Maybe } from "components/Conditionals/Maybe" |
| 5 | +import { LoadingButton } from "components/LoadingButton/LoadingButton" |
| 6 | +import { useTranslation } from "react-i18next" |
2 | 7 | import { Workspace } from "../../api/typesGenerated"
|
3 | 8 | import { combineClasses } from "../../util/combineClasses"
|
4 |
| -import { autoStartDisplay, autoStopDisplay, isShuttingDown, Language } from "../../util/schedule" |
| 9 | +import { autoStartDisplay, autoStopDisplay, isShuttingDown } from "../../util/schedule" |
5 | 10 | import { isWorkspaceOn } from "../../util/workspace"
|
6 | 11 |
|
| 12 | +const AutoStopDisplay = ({ workspace }: { workspace: Workspace }): JSX.Element => { |
| 13 | + const { t } = useTranslation("common") |
| 14 | + const autoStopTime = autoStopDisplay(workspace) |
| 15 | + return ( |
| 16 | + <ChooseOne> |
| 17 | + <Cond condition={isEditing}> |
| 18 | + <> |
| 19 | + <TextField |
| 20 | + value={autoStopTime} |
| 21 | + onChange={} |
| 22 | + /> |
| 23 | + <LoadingButton disabled={}> |
| 24 | + {t("schedule.submitUpdate")} |
| 25 | + </LoadingButton> |
| 26 | + </> |
| 27 | + </Cond> |
| 28 | + <Cond> |
| 29 | + {autoStopTime} |
| 30 | + </Cond> |
| 31 | + </ChooseOne> |
| 32 | + ) |
| 33 | +} |
| 34 | + |
7 | 35 | export const WorkspaceScheduleLabel: React.FC<{ workspace: Workspace }> = ({ workspace }) => {
|
8 | 36 | const styles = useStyles()
|
| 37 | + const { t } = useTranslation("common") |
9 | 38 |
|
10 |
| - if (isWorkspaceOn(workspace)) { |
11 |
| - const stopLabel = autoStopDisplay(workspace) |
12 |
| - const shouldDisplayStrongLabel = !isShuttingDown(workspace) |
13 |
| - |
14 |
| - // If it is shutting down, we don't need to display the auto stop label |
15 |
| - return ( |
| 39 | + return <ChooseOne> |
| 40 | + <Cond condition={isWorkspaceOn(workspace)}> |
16 | 41 | <span className={combineClasses([styles.labelText, "chromatic-ignore"])}>
|
17 |
| - {shouldDisplayStrongLabel && <strong>{Language.autoStopLabel}</strong>}{" "} |
18 |
| - <span className={styles.value}>{stopLabel}</span> |
| 42 | + <Maybe condition={!isShuttingDown(workspace)}> |
| 43 | + <strong>{t("schedule.autoStopLabel")}</strong> |
| 44 | + </Maybe> |
| 45 | + {" "} |
| 46 | + <span className={styles.value}> |
| 47 | + <AutoStopDisplay workspace={workspace} /> |
| 48 | + </span> |
19 | 49 | </span>
|
20 |
| - ) |
21 |
| - } |
22 |
| - |
23 |
| - return ( |
24 |
| - <span className={combineClasses([styles.labelText, "chromatic-ignore"])}> |
25 |
| - <strong>{Language.autoStartLabel}</strong>{" "} |
26 |
| - <span className={styles.value}>{autoStartDisplay(workspace.autostart_schedule)}</span> |
27 |
| - </span> |
28 |
| - ) |
| 50 | + </Cond> |
| 51 | + <Cond> |
| 52 | + <span className={combineClasses([styles.labelText, "chromatic-ignore"])}> |
| 53 | + <strong>{t("schedule.autoStartLabel")}</strong> |
| 54 | + {" "} |
| 55 | + <span className={styles.value}>{autoStartDisplay(workspace.autostart_schedule)}</span> |
| 56 | + </span> |
| 57 | + </Cond> |
| 58 | + </ChooseOne> |
29 | 59 | }
|
30 | 60 |
|
31 | 61 | const useStyles = makeStyles((theme) => ({
|
|
0 commit comments