Skip to content

Commit 6367424

Browse files
tnagorrafrozenhelium
authored andcommitted
Fix UI for options
1 parent a53cef3 commit 6367424

File tree

13 files changed

+106
-87
lines changed

13 files changed

+106
-87
lines changed

manager-dashboard/app/components/ExpandableContainer/styles.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
.header {
1313
flex-grow: 1;
14+
font-size: 1.2rem;
1415
}
1516

1617
.icons {

manager-dashboard/app/views/NewProject/BasicProjectInfoForm/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ function BasicProjectInfoForm(props: Props<PartialProjectFormType>) {
225225
</div>
226226
{(value.projectType === PROJECT_TYPE_FOOTPRINT && value?.customOptions) && (
227227
<Card
228-
title="Define Options"
228+
title="Custom Options"
229229
contentClassName={styles.card}
230230
>
231231
<Heading level={4}>

manager-dashboard/app/views/NewTutorial/CustomOptionInput/CustomOptionPreview/index.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import React from 'react';
2-
import { PartialTutorialFormType } from '#views/NewTutorial/utils';
32
import { iconMap } from '#utils/common';
4-
3+
import {
4+
colorKeyToColorMap,
5+
PartialTutorialFormType,
6+
} from '../../utils';
57
import styles from './styles.css';
68

79
interface Props {
@@ -15,10 +17,13 @@ export default function CustomOptionPreview(props: Props) {
1517

1618
return (
1719
<div className={styles.optionPreview}>
18-
{value?.map((preview) => {
19-
const Icon = preview.icon ? iconMap[preview.icon] : undefined;
20+
{value?.map((preview, index) => {
21+
const Icon = preview.icon
22+
? iconMap[preview.icon]
23+
: iconMap.flagOutline;
24+
2025
const previewText = [
21-
preview.title,
26+
preview.title || `Option ${index + 1}`,
2227
preview.description,
2328
].filter(Boolean).join(' - ');
2429

@@ -30,7 +35,9 @@ export default function CustomOptionPreview(props: Props) {
3035
{Icon && (
3136
<div
3237
className={styles.previewIcon}
33-
style={{ backgroundColor: preview.iconColor }}
38+
style={{
39+
backgroundColor: preview.iconColor || colorKeyToColorMap.gray,
40+
}}
3441
>
3542
<Icon />
3643
</div>

manager-dashboard/app/views/NewTutorial/CustomOptionInput/CustomOptionPreview/styles.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
display: flex;
1818
align-items: center;
1919
border-radius: 50%;
20+
/* FIXME: do not hard code this if possible */
2021
padding: 3px;
2122
font-size: 30px;
2223
}

manager-dashboard/app/views/NewTutorial/CustomOptionInput/SubOption/index.tsx renamed to manager-dashboard/app/views/NewTutorial/CustomOptionInput/SubOptionInput/index.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ interface Props {
2020
onRemove: (index: number) => void;
2121
index: number;
2222
error: Error<PartialSubOptionType> | undefined;
23+
disabled: boolean;
2324
}
2425
export default function SubOption(props: Props) {
2526
const {
@@ -28,6 +29,7 @@ export default function SubOption(props: Props) {
2829
onRemove,
2930
index,
3031
error: riskyError,
32+
disabled,
3133
} = props;
3234

3335
const onReasonChange = useFormObject(index, onChange, { subOptionsId: 1 });
@@ -37,23 +39,26 @@ export default function SubOption(props: Props) {
3739
<div className={styles.subOptionContent}>
3840
<TextInput
3941
className={styles.subOptionInput}
40-
label="Description"
42+
label="Title"
4143
value={value.description}
4244
name={'description' as const}
4345
error={error?.description}
4446
onChange={onReasonChange}
47+
disabled={disabled}
4548
/>
4649
<NumberInput
4750
className={styles.subOptionInput}
4851
label="Value"
4952
value={value.value}
5053
name={'value' as const}
51-
error={error?.description}
54+
error={error?.value}
5255
onChange={onReasonChange}
56+
disabled={disabled}
5357
/>
5458
<Button
5559
name={index}
5660
onClick={onRemove}
61+
disabled={disabled}
5762
>
5863
Remove
5964
</Button>

manager-dashboard/app/views/NewTutorial/CustomOptionInput/SubOption/styles.css renamed to manager-dashboard/app/views/NewTutorial/CustomOptionInput/SubOptionInput/styles.css

File renamed without changes.

manager-dashboard/app/views/NewTutorial/CustomOptionInput/index.tsx

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import NumberInput from '#components/NumberInput';
1515
import SelectInput from '#components/SelectInput';
1616
import NonFieldError from '#components/NonFieldError';
1717

18-
import SubOption from './SubOption';
18+
import SubOptionInput from './SubOptionInput';
1919
import {
2020
ColorOptions,
2121
PartialTutorialFormType,
@@ -26,7 +26,7 @@ import styles from './styles.css';
2626
import { IconItem, iconList } from '#utils/common';
2727

2828
export type PartialCustomOptionsType = NonNullable<PartialTutorialFormType['customOptions']>[number]
29-
const defaultcustomOptionsValue: PartialCustomOptionsType = {
29+
const defaultCustomOptionsValue: PartialCustomOptionsType = {
3030
optionId: 1,
3131
};
3232

@@ -35,21 +35,21 @@ type subOptionsType = NonNullable<PartialCustomOptionsType['subOptions']>[number
3535
interface Props {
3636
value: PartialCustomOptionsType;
3737
onChange: (value: SetValueArg<PartialCustomOptionsType>, index: number) => void;
38-
onRemove: (index: number) => void;
3938
index: number;
4039
error: Error<PartialCustomOptionsType> | undefined;
40+
disabled: boolean;
4141
}
4242

4343
export default function CustomOptionInput(props: Props) {
4444
const {
4545
value,
4646
onChange,
47-
onRemove,
4847
index,
4948
error: riskyError,
49+
disabled,
5050
} = props;
5151

52-
const onOptionChange = useFormObject(index, onChange, defaultcustomOptionsValue);
52+
const onOptionChange = useFormObject(index, onChange, defaultCustomOptionsValue);
5353

5454
const {
5555
setValue: onsubOptionsAdd,
@@ -63,7 +63,7 @@ export default function CustomOptionInput(props: Props) {
6363
[error?.subOptions],
6464
);
6565

66-
const handlesubOptionsAdd = React.useCallback(
66+
const handleSubOptionsAdd = React.useCallback(
6767
() => {
6868
onOptionChange(
6969
(oldValue: PartialCustomOptionsType['subOptions']) => {
@@ -95,6 +95,7 @@ export default function CustomOptionInput(props: Props) {
9595
name={'title' as const}
9696
onChange={onOptionChange}
9797
error={error?.title}
98+
disabled={disabled}
9899
/>
99100
<SelectInput
100101
className={styles.optionIcon}
@@ -106,6 +107,7 @@ export default function CustomOptionInput(props: Props) {
106107
labelSelector={(d: IconItem) => d.label}
107108
onChange={onOptionChange}
108109
error={error?.icon}
110+
disabled={disabled}
109111
/>
110112
</div>
111113
<div className={styles.optionContent}>
@@ -116,6 +118,7 @@ export default function CustomOptionInput(props: Props) {
116118
name={'value' as const}
117119
onChange={onOptionChange}
118120
error={error?.value}
121+
disabled={disabled}
119122
/>
120123
<SelectInput
121124
className={styles.optionIcon}
@@ -127,6 +130,7 @@ export default function CustomOptionInput(props: Props) {
127130
labelSelector={(d: ColorOptions) => d.label}
128131
onChange={onOptionChange}
129132
error={error?.iconColor}
133+
disabled={disabled}
130134
/>
131135
</div>
132136
<TextInput
@@ -136,14 +140,9 @@ export default function CustomOptionInput(props: Props) {
136140
name={'description' as const}
137141
onChange={onOptionChange}
138142
error={error?.description}
143+
disabled={disabled}
139144
/>
140-
<Button
141-
name={index}
142-
onClick={onRemove}
143-
className={styles.removeButton}
144-
>
145-
Remove Option
146-
</Button>
145+
{/* FIXME: use accordion open by default */}
147146
<div className={styles.subOptions}>
148147
<Heading level={5}>
149148
Sub Options
@@ -152,13 +151,14 @@ export default function CustomOptionInput(props: Props) {
152151
error={subOptionsError}
153152
/>
154153
{value.subOptions?.map((sub, i) => (
155-
<SubOption
154+
<SubOptionInput
156155
key={sub.subOptionsId}
157156
value={sub}
158157
index={i}
159158
onChange={onsubOptionsAdd}
160159
onRemove={onsubOptionsRemove}
161160
error={subOptionsError?.[sub.subOptionsId]}
161+
disabled={disabled}
162162
/>
163163
))}
164164
{!value.subOptions?.length && (
@@ -168,8 +168,8 @@ export default function CustomOptionInput(props: Props) {
168168
name="addSubOption"
169169
className={styles.addButton}
170170
icons={<MdAdd />}
171-
onClick={handlesubOptionsAdd}
172-
disabled={value.subOptions && value.subOptions.length >= 6}
171+
onClick={handleSubOptionsAdd}
172+
disabled={disabled || (value.subOptions && value.subOptions.length >= 6)}
173173
>
174174
Add Sub Options
175175
</Button>

manager-dashboard/app/views/NewTutorial/CustomOptionInput/styles.css

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@
1616
}
1717
}
1818

19-
.remove-button {
20-
align-self: end;
21-
width: fit-content;
22-
}
23-
2419
.add-button {
2520
width: fit-content;
2621
}

manager-dashboard/app/views/NewTutorial/InformationPageInput/Block/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import {
66
getErrorObject,
77
} from '@togglecorp/toggle-form';
88

9-
import { PartialBlocksType } from '#views/NewTutorial/utils';
109
import FileInput from '#components/FileInput';
1110
import MarkdownEditor from '#components/MarkdownEditor';
1211

12+
import { PartialBlocksType } from '../../utils';
1313
// import styles from './styles.css';
1414

1515
type PartialBlockType = NonNullable<PartialBlocksType>[number];
@@ -50,7 +50,7 @@ export default function Block(props: Props) {
5050
name={'imageFile' as const}
5151
value={value?.imageFile}
5252
onChange={onBlockChange}
53-
label={`Block ${index + 1}`}
53+
label={`Block #${index + 1}`}
5454
hint="Make sure you have the rights to
5555
use this image. It should end with .jpg or .png."
5656
accept="image/png, image/jpeg"

manager-dashboard/app/views/NewTutorial/InformationPageInput/InformationPagePreview/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import React from 'react';
22

3-
import { PartialTutorialFormType } from '#views/NewTutorial/utils';
43
import MobilePreview from '#components/MobilePreview';
54
import Preview from '#components/Preview';
5+
import MarkdownPreview from '#components/MarkdownPreview';
66

7+
import { PartialTutorialFormType } from '../../utils';
78
import styles from './styles.css';
8-
import MarkdownPreview from '#components/MarkdownPreview';
99

1010
interface Props {
1111
value: NonNullable<PartialTutorialFormType['informationPages']>[number];

0 commit comments

Comments
 (0)