teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

文章訂正

2021/11/17 15:05

投稿

edu
edu

スコア35

title CHANGED
@@ -1,1 +1,1 @@
1
- 基本情報力の回答を確認画面で表示したい。
1
+ 相談内容を記した内容を確認画面で表示したい。
body CHANGED
@@ -1,85 +1,46 @@
1
1
  ReactでMaterial-UI を使用して、Web フォームを作成しています。
2
2
 
3
- 基本情報入力の回答と相談内容を確認画面で表示したい。
3
+ **相談内容を記入した内容を確認画面 (Content.js / case3) で表示したい。**
4
4
  どのように実装したら良いかわからない状況で、詰まっています。 アドバイスをお願いします。
5
5
 
6
6
  問題解決のため行なったこと
7
7
 
8
- Basic コンポーネントは中で state を扱えていないので、Questionnaire.jsを参考にした。
8
+ Optional コンポーネントは中で state を扱えていないので、Questionnaire.jsを参考にした。
9
9
  また、渡すべき state を React.useState() で作ったり、それを props で渡していないので、
10
10
  表示する以前に回答の保存ができていないので、Questionnaire.jsを参考にして実装したが、
11
11
  基本情報入力の回答を確認画面で表示できなかった。
12
12
 
13
- **Basic.js**
13
+ **Optional。js**
14
14
  ```
15
15
  import React from "react";
16
- import Radio from "@mui/material/Radio";
16
+ import { Grid } from "@mui/material";
17
- import RadioGroup from "@mui/material/RadioGroup";
18
- import FormControlLabel from "@mui/material/FormControlLabel";
19
- import FormControl from "@mui/material/FormControl";
20
- import FormLabel from "@mui/material/FormLabel";
21
- import InputLabel from "@mui/material/InputLabel";
22
- import Select from "@mui/material/Select";
17
+ import Tooltip from "@mui/material/Tooltip";
18
+ import TextField from "@mui/material/TextField";
23
19
 
24
- const Basic = ({ basicProfile, setBasicProfile }) => {
20
+ const Optional = ({ request, setRequest }) => {
25
21
  return (
26
- <>
22
+ <div>
27
- <div style={{ textAlign: "center" }}>
28
- <FormControl component="fieldset">
29
- <FormLabel component="legend">- 性別 -</FormLabel>
30
- <RadioGroup row aria-label="gender" name="row-radio-buttons-group">
31
- <FormControlLabel value="male" control={<Radio />} label="男性" />
32
- <FormControlLabel value="female" control={<Radio />} label="女性" />
33
- </RadioGroup>
23
+ <Grid container>
24
+ <Grid sm={2} />
25
+ <Grid lg={8} sm={8} spacing={10}>
26
+ <Tooltip title="ご相談内容を記入することができます" placement="top-start" arrow>
27
+ <TextField
28
+ label="ご相談内容"
29
+ fullWidth
30
+ margin="normal"
31
+ rows={4}
32
+ multiline
33
+ variant="outlined"
34
+ placeholder="その他ご要望等あれば、ご記入ください"
35
+
36
+ />
34
- </FormControl>
37
+ </Tooltip>
38
+ </Grid>
39
+ </Grid>
35
- </div>
40
+ </div>
36
- <div style={{ textAlign: "center" }}>
37
- <FormLabel component="legend">- 生年月日 -</FormLabel>
38
- <FormControl sx={{ m: 1, minWidth: 120 }}>
39
- <InputLabel htmlFor="grouped-native-select">year</InputLabel>
40
- <Select native defaultValue="" id="grouped-native-select" label="Grouping">
41
- <option aria-label="None" value="" />
42
- <optgroup label="year">
43
- {Array.from(Array(2020), (_, num) => (
44
- <option key={num} value={num + 1}>
45
- {num + 1990}
46
- </option>
47
- ))}
48
- </optgroup>
49
- </Select>
50
- </FormControl>
51
- <FormControl sx={{ m: 1, minWidth: 120 }}>
52
- <InputLabel htmlFor="grouped-native-select">month</InputLabel>
53
- <Select native defaultValue="" id="grouped-native-select" label="Grouping">
54
- <option aria-label="None" value="" />
55
- <optgroup label="month">
56
- {Array.from(Array(12), (_, num) => (
57
- <option key={num} value={num + 1}>
58
- {num + 1}
59
- </option>
60
- ))}
61
- </optgroup>
62
- </Select>
63
- </FormControl>
64
- <FormControl sx={{ m: 1, minWidth: 120 }}>
65
- <InputLabel htmlFor="grouped-native-select">day</InputLabel>
66
- <Select native defaultValue="" id="grouped-native-select" label="Grouping">
67
- <option aria-label="None" value="" />
68
- <optgroup label="day">
69
- {Array.from(Array(12), (_, num) => (
70
- <option key={num} value={num + 1}>
71
- {num + 1}
72
- </option>
73
- ))}
74
- </optgroup>
75
- </Select>
76
- </FormControl>
77
- </div>
78
- </>
79
41
  );
80
42
  };
81
-
82
- export default Basic;
43
+ export default Optional;
83
44
  ```
84
45
  **Content.js**
85
46
 

2

文章訂正

2021/11/17 15:05

投稿

edu
edu

スコア35

title CHANGED
@@ -1,1 +1,1 @@
1
- " Failed to compile " 改善したい。
1
+ 基本情報入力の回答確認画面で表示したい。
body CHANGED
@@ -1,18 +1,15 @@
1
1
  ReactでMaterial-UI を使用して、Web フォームを作成しています。
2
2
 
3
- **期待する動作**
3
+ 基本情報入力の回答と相談内容を確認画面で表示したい。
4
- Basic.js 質問及び答えた回答をContent.js case3で表示したく、実装ていたら、下記のエラー表示が出それ改善したい。
4
+ ように実装したら良いかわからない状況で詰まっいます。 アドバイスお願します
5
5
 
6
- どのように実装したら良いかわからない状況で、詰まっています。 何方かアドバイスをお願いします。
7
- ```
8
- Failed to compile
6
+ 問題解決のため行なったこと
9
- src/components/Content.js
10
- Line 19:39: 'basicProfile' is not defined no-undef
11
- Line 19:53: 'setBasicProfile' is not defined no-undef
12
- Line 27:35: 'basicProfile' is not defined no-undef
13
- Line 27:49: 'setBasicProfile' is not defined no-undef
14
- ```
15
7
 
8
+ Basic コンポーネントは中で state を扱えていないので、Questionnaire.jsを参考にした。
9
+ また、渡すべき state を React.useState() で作ったり、それを props で渡していないので、
10
+ 表示する以前に回答の保存ができていないので、Questionnaire.jsを参考にして実装したが、
11
+ 基本情報入力の回答を確認画面で表示できなかった。
12
+
16
13
  **Basic.js**
17
14
  ```
18
15
  import React from "react";
@@ -105,7 +102,7 @@
105
102
  const StepContent = ({ stepIndex, basicProps, questionnaireProps, optionalProps }) => {
106
103
  switch (stepIndex) {
107
104
  case 0:
108
- return <Basic {...basicProps={ basicProfile, setBasicProfile }} />
105
+ return <Basic {...basicProps} />
109
106
  case 1:
110
107
  return <Questionnaire {...questionnaireProps} />;
111
108
  case 2:
@@ -113,7 +110,7 @@
113
110
  case 3:
114
111
  return (
115
112
  <div style={{ textAlign: "center" }}>
116
- <Basic {...basicProps={ basicProfile, setBasicProfile }} />
113
+ <Basic {...basicProps} />
117
114
  <Questionnaire {...questionnaireProps} />
118
115
  <Optional {...optionalProps} />
119
116
  </div>
@@ -126,6 +123,7 @@
126
123
  const [activeStep, setActiveStep] = React.useState(0);
127
124
  const [basicProfile, setBasicProfile] = React.useState({ gender: null, year: null, month: null, day: null });
128
125
  const [answers, setAnswers] = React.useState(Array(QUESTIONS.length).fill(null));
126
+ // const [request, setRequest] = React.useState();
129
127
  const steps = getSteps();
130
128
  const handleNext = () => {
131
129
  setActiveStep((prevActiveStep) => prevActiveStep + 1);
@@ -156,7 +154,7 @@
156
154
  ) : (
157
155
  <div>
158
156
  <Typography>
159
- <StepContent stepIndex={activeStep} questionnaireProps={{ answers, setAnswers }} />
157
+ <StepContent stepIndex={activeStep} questionnaireProps={{ answers, setAnswers }} basicProps={{ basicProfile, setBasicProfile }} />
160
158
  </Typography>
161
159
  <Button disabled={activeStep === 0} onClick={handleBack}>
162
160
  戻る

1

文章訂正

2021/11/17 07:50

投稿

edu
edu

スコア35

title CHANGED
File without changes
body CHANGED
@@ -88,71 +88,87 @@
88
88
 
89
89
  ```
90
90
  import React from "react";
91
+ import { Grid } from "@mui/material";
92
+ import Stepper from "@mui/material/Stepper";
91
- import Radio from "@mui/material/Radio";
93
+ import Step from "@mui/material/Step";
92
- import RadioGroup from "@mui/material/RadioGroup";
93
- import FormControlLabel from "@mui/material/FormControlLabel";
94
- import FormControl from "@mui/material/FormControl";
95
- import FormLabel from "@mui/material/FormLabel";
94
+ import StepLabel from "@mui/material/StepLabel";
96
- import InputLabel from "@mui/material/InputLabel";
97
- import Select from "@mui/material/Select";
95
+ import Button from "@mui/material/Button";
96
+ import Typography from "@mui/material/Typography";
97
+ import Basic from "./Basic";
98
+ import Questionnaire, { QUESTIONS } from "./Questionnaire";
99
+ import Optional from "./Optional";
98
100
 
101
+ function getSteps() {
102
+ return ["お客様の情報を入力して下さい", "以下にお答え下さい", "ご相談下さい", "以下の内容をご確認下さい"];
103
+ }
104
+
105
+ const StepContent = ({ stepIndex, basicProps, questionnaireProps, optionalProps }) => {
106
+ switch (stepIndex) {
107
+ case 0:
108
+ return <Basic {...basicProps={ basicProfile, setBasicProfile }} />
109
+ case 1:
110
+ return <Questionnaire {...questionnaireProps} />;
111
+ case 2:
112
+ return <Optional {...optionalProps}/>;
113
+ case 3:
114
+ return (
115
+ <div style={{ textAlign: "center" }}>
99
- const Basic = ({ basicProfile, setBasicProfile }) => {
116
+ <Basic {...basicProps={ basicProfile, setBasicProfile }} />
117
+ <Questionnaire {...questionnaireProps} />
118
+ <Optional {...optionalProps} />
119
+ </div>
120
+ );
121
+ default:
122
+ return "Unknown stepIndex";
123
+ }
124
+ };
125
+ function Content() {
126
+ const [activeStep, setActiveStep] = React.useState(0);
127
+ const [basicProfile, setBasicProfile] = React.useState({ gender: null, year: null, month: null, day: null });
128
+ const [answers, setAnswers] = React.useState(Array(QUESTIONS.length).fill(null));
129
+ const steps = getSteps();
130
+ const handleNext = () => {
131
+ setActiveStep((prevActiveStep) => prevActiveStep + 1);
132
+ };
133
+ const handleBack = () => {
134
+ setActiveStep((prevActiveStep) => prevActiveStep - 1);
135
+ };
136
+ const handleReset = () => {
137
+ setActiveStep(0);
138
+ };
139
+ const buttonDisabled = activeStep === 1 && answers.some((a) => !a);
100
140
  return (
141
+ <Grid container>
142
+ <Grid sm={2} />
143
+ <Grid lg={8} sm={8} spacing={10}>
144
+ <Stepper activeStep={activeStep} alternativeLabel>
145
+ {steps.map((label) => (
146
+ <Step key={label}>
147
+ <StepLabel>{label}</StepLabel>
101
- <>
148
+ </Step>
149
+ ))}
150
+ </Stepper>
151
+ {activeStep === steps.length ? (
102
- <div style={{ textAlign: "center" }}>
152
+ <div style={{ textAlign: "center" }}>
103
- <FormControl component="fieldset">
153
+ <Typography>全ステップの表示を完了</Typography>
104
- <FormLabel component="legend">- 性別 -</FormLabel>
154
+ <Button onClick={handleReset}>リセット</Button>
105
- <RadioGroup row aria-label="gender" name="row-radio-buttons-group">
106
- <FormControlLabel value="male" control={<Radio />} label="男性" />
107
- <FormControlLabel value="female" control={<Radio />} label="女性" />
108
- </RadioGroup>
109
- </FormControl>
110
- </div>
155
+ </div>
156
+ ) : (
157
+ <div>
158
+ <Typography>
159
+ <StepContent stepIndex={activeStep} questionnaireProps={{ answers, setAnswers }} />
160
+ </Typography>
111
- <div style={{ textAlign: "center" }}>
161
+ <Button disabled={activeStep === 0} onClick={handleBack}>
112
- <FormLabel component="legend">- 生年月日 -</FormLabel>
113
- <FormControl sx={{ m: 1, minWidth: 120 }}>
114
- <InputLabel htmlFor="grouped-native-select">year</InputLabel>
115
- <Select native defaultValue="" id="grouped-native-select" label="Grouping">
116
- <option aria-label="None" value="" />
117
- <optgroup label="year">
118
- {Array.from(Array(2020), (_, num) => (
119
- <option key={num} value={num + 1}>
120
- {num + 1990}
162
+ 戻る
121
- </option>
163
+ </Button>
122
- ))}
123
- </optgroup>
124
- </Select>
125
- </FormControl>
126
- <FormControl sx={{ m: 1, minWidth: 120 }}>
127
- <InputLabel htmlFor="grouped-native-select">month</InputLabel>
128
- <Select native defaultValue="" id="grouped-native-select" label="Grouping">
164
+ <Button variant="contained" color="primary" onClick={handleNext} disabled={buttonDisabled}>
129
- <option aria-label="None" value="" />
165
+ {activeStep === steps.length - 1 ? "送信" : "次へ"}
130
- <optgroup label="month">
131
- {Array.from(Array(12), (_, num) => (
132
- <option key={num} value={num + 1}>
133
- {num + 1}
134
- </option>
166
+ </Button>
135
- ))}
136
- </optgroup>
137
- </Select>
138
- </FormControl>
139
- <FormControl sx={{ m: 1, minWidth: 120 }}>
140
- <InputLabel htmlFor="grouped-native-select">day</InputLabel>
141
- <Select native defaultValue="" id="grouped-native-select" label="Grouping">
142
- <option aria-label="None" value="" />
143
- <optgroup label="day">
144
- {Array.from(Array(12), (_, num) => (
145
- <option key={num} value={num + 1}>
146
- {num + 1}
147
- </option>
148
- ))}
149
- </optgroup>
150
- </Select>
151
- </FormControl>
152
- </div>
167
+ </div>
168
+ )}
153
- </>
169
+ </Grid>
170
+ </Grid>
154
171
  );
155
- };
172
+ }
156
-
157
- export default Basic;
173
+ export default Content;
158
174
  ```