feat: complete employee invite flow implementation

- Fix submitEmployeeAnswers to use pending invites and consume during submission
- Add automatic employee report generation with company context
- Include company onboarding data in LLM prompts for alignment analysis
- Store reports in correct Firestore collection with submission linking
- Simplify frontend invite submission to single API call
- Add comprehensive error handling and employee creation
This commit is contained in:
Ra
2025-08-25 14:48:52 -07:00
parent 0d7b8d104b
commit cf670c84b3
2 changed files with 222 additions and 25 deletions

View File

@@ -81,31 +81,14 @@ const EmployeeQuestionnaire: React.FC = () => {
const submitViaInvite = async (answers: EmployeeSubmissionAnswers, inviteCode: string) => {
try {
// First, consume the invite to mark it as used
const consumeResponse = await fetch(`${API_URL}/consumeInvitation`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ code: inviteCode })
});
if (!consumeResponse.ok) {
throw new Error('Failed to process invitation');
}
// Get orgId from the consume response
const consumeData = await consumeResponse.json();
const orgId = consumeData.orgId;
// Submit the questionnaire answers using Cloud Function
// This will include company onboarding questions and answers for LLM context
// Submit the questionnaire answers directly using Cloud Function
// The cloud function will handle invite consumption and report generation
const submitResponse = await fetch(`${API_URL}/submitEmployeeAnswers`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
inviteCode: inviteCode,
answers: answers,
orgId: orgId,
includeCompanyContext: true // Flag to include company Q&A in LLM processing
answers: answers
})
});
@@ -115,7 +98,7 @@ const EmployeeQuestionnaire: React.FC = () => {
}
const result = await submitResponse.json();
return { success: true, reportGenerated: !!result.report };
return { success: true, reportGenerated: true };
} catch (error) {
console.error('Invite submission error:', error);
return { success: false, error: error.message };