Files
overleaf-cep/services/web/app/src/Features/OnboardingDataCollection/OnboardingDataCollectionManager.js
Domagoj Kriskovic d6b6a160a7 Default LaTeX beginners to the Visual Editor (#18917)
* open visual code if user havent used latex before

* test tooltip on code editor switch

* firstTimeLoadedEditor

* track editor.codeEditorOpened value

* lastEditorLoadedDate

* odc data loaded from mongo

* fix a typo

* use tutorial to check if it was dissmised

* use getInactiveTutorials fn

* fix test

* check if code editor was opened

* added translations

* pass classname to tooltip

* use signUpDate instead of lastEditorLoadedDate

* refactor visual fallback value

* use tutorial completed data only for tooltip

* set lastUsedMode in odc form

* safer usedLatex check

* getOnboardingDataValue helper function

* move tooltip to a separate component

* move classname to tooltipProps

* usedLatex in meta tag

* codeEdtiorOpened fallback value

* fix release date year

* fix 24 hours criteria for showing the tooltip

* fix tests

* hide tooltip when code editor is opened

* remove setting lastUsedMode in ODC form

* remove empty comment

* change date for checking signUpDate

* fix linting error

GitOrigin-RevId: 0a57ba3f4717492d4546633571117f667d3a05f8
2024-08-02 08:05:10 +00:00

78 lines
1.7 KiB
JavaScript

const {
OnboardingDataCollection,
OnboardingDataCollectionSchema,
} = require('../../models/OnboardingDataCollection')
const OError = require('@overleaf/o-error')
async function getOnboardingDataCollection(userId, projection = {}) {
try {
return await OnboardingDataCollection.findOne(
{ _id: userId },
projection
).exec()
} catch (error) {
throw OError.tag(error, 'Failed to get OnboardingDataCollection')
}
}
async function getOnboardingDataValue(userId, key) {
if (!OnboardingDataCollectionSchema.paths[key]) {
throw new Error(`${key} is not a valid onboarding data key`)
}
const result = await getOnboardingDataCollection(userId, { [key]: 1 })
return result ? result[key] : null
}
async function upsertOnboardingDataCollection({
userId,
firstName,
lastName,
usedLatex,
primaryOccupation,
companyDivisionDepartment,
companyJobTitle,
governmentJobTitle,
institutionName,
otherJobTitle,
nonprofitDivisionDepartment,
nonprofitJobTitle,
role,
subjectArea,
updatedAt,
}) {
const odc = await OnboardingDataCollection.findOneAndUpdate(
{ _id: userId },
{
firstName,
lastName,
usedLatex,
primaryOccupation,
companyDivisionDepartment,
companyJobTitle,
governmentJobTitle,
institutionName,
otherJobTitle,
nonprofitDivisionDepartment,
nonprofitJobTitle,
role,
subjectArea,
updatedAt,
},
{ upsert: true }
)
return odc
}
function deleteOnboardingDataCollection(id) {
return OnboardingDataCollection.deleteOne({ _id: id })
}
module.exports = {
getOnboardingDataCollection,
upsertOnboardingDataCollection,
deleteOnboardingDataCollection,
getOnboardingDataValue,
}