[web] interviews/study-list: throw error when starting/stopping without session
This commit is contained in:
parent
46aa4bd135
commit
27a6bbdf98
|
|
@ -127,8 +127,9 @@ export default function QuestionProgressAction({
|
|||
deleteProgressMutation.mutate(
|
||||
{ format: metadata.format, listKey, slug: metadata.slug },
|
||||
{
|
||||
onError: () => {
|
||||
onError: (error) => {
|
||||
showToast({
|
||||
description: error.message,
|
||||
title: intl.formatMessage({
|
||||
defaultMessage:
|
||||
'Failed to mark question as incomplete. Please try again',
|
||||
|
|
@ -142,10 +143,10 @@ export default function QuestionProgressAction({
|
|||
onSuccess: () => {
|
||||
showToast({
|
||||
title: intl.formatMessage({
|
||||
defaultMessage: 'Marked question as incomplete!',
|
||||
defaultMessage: 'Marked question as incomplete',
|
||||
description:
|
||||
'Success message shown when a question is marked as complete',
|
||||
id: 'UZVSxt',
|
||||
id: 'oR0ECI',
|
||||
}),
|
||||
variant: 'info',
|
||||
});
|
||||
|
|
@ -181,14 +182,14 @@ export default function QuestionProgressAction({
|
|||
slug: metadata.slug,
|
||||
},
|
||||
{
|
||||
onError: () => {
|
||||
onError: (error) => {
|
||||
showToast({
|
||||
description: error.message,
|
||||
title: intl.formatMessage({
|
||||
defaultMessage:
|
||||
'Failed to mark question as complete. Please try again',
|
||||
defaultMessage: 'Failed to mark question as complete',
|
||||
description:
|
||||
'Error message shown when a question has failed to mark as complete',
|
||||
id: 'KY8GB9',
|
||||
id: 'mFyOK6',
|
||||
}),
|
||||
variant: 'danger',
|
||||
});
|
||||
|
|
@ -196,10 +197,10 @@ export default function QuestionProgressAction({
|
|||
onSuccess: () => {
|
||||
showToast({
|
||||
title: intl.formatMessage({
|
||||
defaultMessage: 'Marked question as complete!',
|
||||
defaultMessage: 'Marked question as complete',
|
||||
description:
|
||||
'Success message shown when a question was marked as complete',
|
||||
id: 'wxtWHx',
|
||||
id: '3fkhgw',
|
||||
}),
|
||||
variant: 'success',
|
||||
});
|
||||
|
|
|
|||
|
|
@ -779,6 +779,10 @@
|
|||
"defaultMessage": "Page name must contain at least {minLength} character(s).",
|
||||
"description": "Error message"
|
||||
},
|
||||
"3fkhgw": {
|
||||
"defaultMessage": "Marked question as complete",
|
||||
"description": "Success message shown when a question was marked as complete"
|
||||
},
|
||||
"3gL2Vm": {
|
||||
"defaultMessage": "Join Reddit community",
|
||||
"description": "Label for join reddit"
|
||||
|
|
@ -3235,10 +3239,6 @@
|
|||
"defaultMessage": "Software Engineer",
|
||||
"description": "Placeholder for \"Job Title\" input on Projects profile onboarding page"
|
||||
},
|
||||
"KY8GB9": {
|
||||
"defaultMessage": "Failed to mark question as complete. Please try again",
|
||||
"description": "Error message shown when a question has failed to mark as complete"
|
||||
},
|
||||
"KZWEcx": {
|
||||
"defaultMessage": "Please enter a different email address.",
|
||||
"description": "Email validation error message"
|
||||
|
|
@ -4831,10 +4831,6 @@
|
|||
"defaultMessage": "Homepage",
|
||||
"description": "Placeholder for name field of the deployment url"
|
||||
},
|
||||
"UZVSxt": {
|
||||
"defaultMessage": "Marked question as incomplete!",
|
||||
"description": "Success message shown when a question is marked as complete"
|
||||
},
|
||||
"UbCsf6": {
|
||||
"defaultMessage": "Stack",
|
||||
"description": "Label for tech stack used in project"
|
||||
|
|
@ -7511,6 +7507,10 @@
|
|||
"defaultMessage": "<count>{questionCount}</count> <questions>questions</questions>",
|
||||
"description": "Number of questions"
|
||||
},
|
||||
"mFyOK6": {
|
||||
"defaultMessage": "Failed to mark question as complete",
|
||||
"description": "Error message shown when a question has failed to mark as complete"
|
||||
},
|
||||
"mGYl8O": {
|
||||
"defaultMessage": "Upvoted successfully!",
|
||||
"description": "Successful upvote toaster"
|
||||
|
|
@ -7811,6 +7811,10 @@
|
|||
"defaultMessage": "You have unlocked this Figma file",
|
||||
"description": "Tooltip for premium Figma file download button"
|
||||
},
|
||||
"oR0ECI": {
|
||||
"defaultMessage": "Marked question as incomplete",
|
||||
"description": "Success message shown when a question is marked as complete"
|
||||
},
|
||||
"oS10TF": {
|
||||
"defaultMessage": "Follow us on GitHub",
|
||||
"description": "Title for task"
|
||||
|
|
@ -9091,10 +9095,6 @@
|
|||
"defaultMessage": "Dashboard",
|
||||
"description": "Title of Projects Dashboard page"
|
||||
},
|
||||
"wxtWHx": {
|
||||
"defaultMessage": "Marked question as complete!",
|
||||
"description": "Success message shown when a question was marked as complete"
|
||||
},
|
||||
"wzQGxj": {
|
||||
"defaultMessage": "Start in minutes",
|
||||
"description": "Button leading user to sign up to be an affiliate on the Hero section of the 'Become An Affiliate' page"
|
||||
|
|
|
|||
|
|
@ -30,59 +30,57 @@ export const questionProgressRouter = router({
|
|||
return null;
|
||||
}
|
||||
|
||||
const createData = {
|
||||
format,
|
||||
slug,
|
||||
status: 'complete',
|
||||
userId: viewer.id,
|
||||
};
|
||||
let questionProgress = null;
|
||||
if (listKey == null) {
|
||||
const createData = {
|
||||
format,
|
||||
slug,
|
||||
status: 'complete',
|
||||
userId: viewer.id,
|
||||
};
|
||||
let questionProgress = null;
|
||||
|
||||
if (!progressId) {
|
||||
questionProgress = await prisma.questionProgress.create({
|
||||
data: createData,
|
||||
});
|
||||
} else {
|
||||
questionProgress = await prisma.questionProgress.upsert({
|
||||
create: createData,
|
||||
update: {
|
||||
status,
|
||||
},
|
||||
where: {
|
||||
id: progressId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if (listKey != null) {
|
||||
try {
|
||||
const session = await prisma.learningSession.findFirst({
|
||||
if (!progressId) {
|
||||
questionProgress = await prisma.questionProgress.create({
|
||||
data: createData,
|
||||
});
|
||||
} else {
|
||||
questionProgress = await prisma.questionProgress.upsert({
|
||||
create: createData,
|
||||
update: {
|
||||
status,
|
||||
},
|
||||
where: {
|
||||
key: listKey,
|
||||
status: 'IN_PROGRESS',
|
||||
userId: viewer.id,
|
||||
id: progressId,
|
||||
},
|
||||
});
|
||||
|
||||
if (session != null) {
|
||||
await prisma.learningSessionProgress.create({
|
||||
data: {
|
||||
key: hashQuestion(format, slug),
|
||||
sessionId: session.id,
|
||||
status: 'COMPLETED',
|
||||
},
|
||||
});
|
||||
}
|
||||
} catch {
|
||||
// TODO: Report error
|
||||
}
|
||||
|
||||
return {
|
||||
...questionProgress,
|
||||
format: questionProgress.format as QuestionFormat,
|
||||
status: questionProgress.status as QuestionProgressStatus,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
...questionProgress,
|
||||
format: questionProgress.format as QuestionFormat,
|
||||
status: questionProgress.status as QuestionProgressStatus,
|
||||
};
|
||||
const session = await prisma.learningSession.findFirst({
|
||||
where: {
|
||||
key: listKey,
|
||||
status: 'IN_PROGRESS',
|
||||
userId: viewer.id,
|
||||
},
|
||||
});
|
||||
|
||||
if (session == null) {
|
||||
throw 'No ongoing learning session. Start tracking progress first.';
|
||||
}
|
||||
|
||||
return await prisma.learningSessionProgress.create({
|
||||
data: {
|
||||
key: hashQuestion(format, slug),
|
||||
sessionId: session.id,
|
||||
status: 'COMPLETED',
|
||||
},
|
||||
});
|
||||
},
|
||||
),
|
||||
delete: userProcedure
|
||||
|
|
@ -104,7 +102,7 @@ export const questionProgressRouter = router({
|
|||
});
|
||||
|
||||
if (session == null) {
|
||||
return;
|
||||
throw 'No ongoing learning session. Start tracking progress first.';
|
||||
}
|
||||
|
||||
return await prisma.learningSessionProgress.deleteMany({
|
||||
|
|
|
|||
Loading…
Reference in New Issue