Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor code to use response.json() instead of response.text() in Jo… #32

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export default function JoinRetroPage() {
});

if (response.ok) {
const retroCode = await response.text();
const json = await response.json();
const retroCode = json.code;
setSharedRetroCode(retroCode);
setRetroCode(retroCode);
setCurrentDate(new Date().toLocaleDateString());
Expand All @@ -57,8 +58,6 @@ export default function JoinRetroPage() {
setLoading(true);
setError(null);
try {
await initializeRetroSession(); // generate and validate a new retro code

if (isValidRetroCode) {
navigate(`/retro/${retroCodeValue}`);
} else {
Expand Down Expand Up @@ -111,13 +110,13 @@ export default function JoinRetroPage() {
const newRetroCode = e.target.value;
setRetroCode(newRetroCode);
setSharedRetroCode(newRetroCode);
setIsValidRetroCode(true);
}}
/>
<button
className="retro-button submit-button"
type="button"
onClick={handleSubmit}
disabled={!retroCodeValue.trim() || loading || !isValidRetroCode}
>
Submit
</button>
Expand Down
5 changes: 1 addition & 4 deletions packages/client/src/containers/RetroPage/RetroPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const questions = [
];

function RetroPage() {
const [selectedQuestions, setSelectedQuestions] = useState([]);
const [comments, setComments] = useState({});
const [joinCode, setJoinCode] = useState('');
const [inputValues, setInputValues] = useState({});
Expand All @@ -32,7 +31,6 @@ function RetroPage() {
if (response.ok) {
const newRetroCode = await response.text();
setRetroCode(newRetroCode);
setSelectedQuestions(questions);
} else {
throw new Error('Invalid retro code');
}
Expand Down Expand Up @@ -75,7 +73,6 @@ function RetroPage() {
const retroSession = await response.json();

setRetroCode(retroSession.retroCode);
setSelectedQuestions(retroSession.questions);
setComments(retroSession.comments || {});
setJoinCode('');
setErrorMessage('');
Expand Down Expand Up @@ -126,7 +123,7 @@ function RetroPage() {
</button>
</div>
<div className="questionsContainer">
{selectedQuestions.map((question, index) => (
{questions.map((question, index) => (
<div key={question.id} className={`container container${index + 1}`}>
<div className="question">{question.text}</div>
<div className={`box box${index + 1}`}>
Expand Down
2 changes: 1 addition & 1 deletion packages/server/api/routes/retro.router.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ router.get('/', (req, res, next) => {
router.post('/generateRetroCode', (req, res) => {
retroController
.generateRetroCode()
.then((result) => res.json(result))
.then((result) => res.json({ code: result }))
.catch((error) => {
// eslint-disable-next-line no-console
console.log(error);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = function (knex) {
return knex.schema.createTable('RetroParticipants', (table) => {
table.increments('id').primary();
table.integer('retro_id').unsigned().notNullable();
table.integer('team_member_id').unsigned().notNullable();

table.foreign('retro_id').references('id').inTable('Retro');
table.foreign('team_member_id').references('id').inTable('TeamMembers');
});
};

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = function (knex) {
return knex.schema.dropTable('RetroParticipants');
};
Loading