diff --git a/src/main/services/app-state.service.ts b/src/main/services/app-state.service.ts index a94f1b0b..84f4fb29 100644 --- a/src/main/services/app-state.service.ts +++ b/src/main/services/app-state.service.ts @@ -163,6 +163,7 @@ export class AppStateService { // needs the trim at all, to keep whitespace from reading as a set profile. hasProfileData: interviewConfig.profileData.length > 0 && interviewConfig.profileData.trim() !== '', + hasContextData: interviewConfig.context.length > 0 && interviewConfig.context.trim() !== '', }, }; } diff --git a/src/main/types/app-state.ts b/src/main/types/app-state.ts index 60ee72dd..193bf564 100644 --- a/src/main/types/app-state.ts +++ b/src/main/types/app-state.ts @@ -86,6 +86,7 @@ export interface InterviewConfig { export interface InterviewConfigSummary { fullName: string; hasProfileData: boolean; + hasContextData: boolean; } export interface AppState { diff --git a/src/renderer/components/custom/change-password-dialog.tsx b/src/renderer/components/custom/change-password-dialog.tsx deleted file mode 100644 index 99460f6a..00000000 --- a/src/renderer/components/custom/change-password-dialog.tsx +++ /dev/null @@ -1,158 +0,0 @@ -import { useState } from 'react'; -import { toast } from 'sonner'; - -import { InputPassword } from '@/components/custom/input-password'; -import { Button } from '@/components/ui/button'; -import { - Dialog, - DialogContent, - DialogDescription, - DialogFooter, - DialogHeader, - DialogTitle, -} from '@/components/ui/dialog'; -import { useT } from '@/i18n'; - -interface ChangePasswordDialogProps { - open: boolean; - onOpenChange: (open: boolean) => void; - onChangePassword: (currentPassword: string, newPassword: string) => Promise; - loading: boolean; - error: string | null; -} - -export function ChangePasswordDialog({ - open, - onOpenChange, - onChangePassword, - loading, - error, -}: ChangePasswordDialogProps) { - const t = useT(); - const [currentPassword, setCurrentPassword] = useState(''); - const [newPassword, setNewPassword] = useState(''); - const [confirmPassword, setConfirmPassword] = useState(''); - - const handleSubmit = async () => { - try { - if (await onChangePassword(currentPassword, newPassword)) { - toast.success(t.changePassword.succeeded); - } else { - toast.error(t.changePassword.failed); - } - } catch (err) { - // Error is handled by parent component - console.error('Password change failed:', err); - } - }; - - const handleOpenChange = (newOpen: boolean) => { - if (!newOpen) { - // Clear form when closing - setCurrentPassword(''); - setNewPassword(''); - setConfirmPassword(''); - } - onOpenChange(newOpen); - }; - - const passwordsMismatch = confirmPassword !== '' && newPassword !== confirmPassword; - - return ( - - - - {t.changePassword.title} - {t.changePassword.description} - -
-
- -
- setCurrentPassword(e.target.value)} - placeholder={t.changePassword.currentPlaceholder} - maxLength={128} - /> -
-
-
- -
- setNewPassword(e.target.value)} - placeholder={t.changePassword.nextPlaceholder} - maxLength={128} - /> -
-
-
- -
- setConfirmPassword(e.target.value)} - placeholder={t.changePassword.confirmPlaceholder} - maxLength={128} - /> -
-
-
- - - - - {/* Says why the button is dead. A mismatch is the one condition above that the user - cannot see from the fields themselves - both are masked - so without this the - dialog silently refuses to submit and gives no reason. Held back until the confirm - field has something in it, so it is not an error for a half-typed entry. */} - {passwordsMismatch && ( -
- {t.changePassword.mismatch} -
- )} - {error && ( -
- {error} -
- )} -
-
- ); -} diff --git a/src/renderer/components/custom/command-palette.tsx b/src/renderer/components/custom/command-palette.tsx index c14e33ef..23e5d1cd 100644 --- a/src/renderer/components/custom/command-palette.tsx +++ b/src/renderer/components/custom/command-palette.tsx @@ -191,8 +191,10 @@ export function CommandPalette() { {t.commandPalette.startMock} )} + {/* Through home, like the mock entry: the context confirmation is asked there, + before anything navigates to `/main`. */} run(() => navigate('/main', { state: { autoStartLive: true } }))} + onSelect={() => run(() => navigate('/', { state: { openLiveStart: true } }))} > {t.commandPalette.startLive} diff --git a/src/renderer/components/custom/context-reminder-dialog.tsx b/src/renderer/components/custom/context-reminder-dialog.tsx new file mode 100644 index 00000000..365731e5 --- /dev/null +++ b/src/renderer/components/custom/context-reminder-dialog.tsx @@ -0,0 +1,207 @@ +import { FileText, Play } from 'lucide-react'; +import { useEffect, useState } from 'react'; + +import { Button } from '@/components/ui/button'; +import { + Dialog, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, +} from '@/components/ui/dialog'; +import { useT } from '@/i18n'; +import { getElectron } from '@/lib/utils'; + +interface ContextReminderDialogProps { + open: boolean; + onOpenChange: (open: boolean) => void; + /** Picks the copy: an empty context is reported as missing, a set one is asked about. */ + hasContext: boolean; + onProceed: () => void; + onEditContext: () => void; + /** + * Esc or a click on the overlay. Kept apart from `onOpenChange(false)` for the same reason the + * headphone notice keeps it apart: both buttons close through that too. + */ + onCancel?: () => void; +} + +interface AccountPreview { + fullName: string; + profileData: string; + context: string; +} + +// The CV and the context run to 128,000 characters each; only the opening is rendered, and the +// line clamp below does the visual cut. Sliced first so the DOM never holds the whole thing. +const PREVIEW_CHARS = 400; + +/** + * Raised before every live and mock session to confirm the account's job context fits it. + * + * The context is one account-wide value that outlives the interview it was written for, so a + * set context is not a current one: a candidate moving between applications starts the next + * interview against the last job description, and every suggestion is quietly tailored to the + * wrong role. Nothing downstream can tell, so it is asked every time, like the headphone notice. + * + * The opening of each field is shown so the answer is a glance rather than a recollection. It is + * fetched over `account:get` on open, because the app state carries only a summary. + */ +export default function ContextReminderDialog({ + open, + onOpenChange, + hasContext, + onProceed, + onEditContext, + onCancel, +}: ContextReminderDialogProps) { + const t = useT(); + const [preview, setPreview] = useState(null); + // A failed fetch hides the preview rather than leaving it on "Loading" or reading as "Not set". + const [previewFailed, setPreviewFailed] = useState(false); + + useEffect(() => { + if (!open) return; + let cancelled = false; + void getElectron() + ?.account?.get() + .then((result) => { + if (cancelled) return; + if (!result?.success || !result.data) { + setPreviewFailed(true); + return; + } + setPreviewFailed(false); + setPreview({ + fullName: result.data.fullName, + profileData: result.data.profileData.slice(0, PREVIEW_CHARS), + context: result.data.context.slice(0, PREVIEW_CHARS), + }); + }) + .catch((error) => { + console.error('Failed to load the account preview:', error); + if (!cancelled) setPreviewFailed(true); + }); + return () => { + cancelled = true; + }; + }, [open]); + + const copy = hasContext + ? { + title: t.contextReminder.setTitle, + description: t.contextReminder.setDescription, + edit: t.contextReminder.review, + proceed: t.contextReminder.confirm, + } + : { + title: t.contextReminder.title, + description: t.contextReminder.description, + edit: t.contextReminder.edit, + proceed: t.contextReminder.proceed, + }; + + const handleDismiss = () => { + onOpenChange(false); + onCancel?.(); + }; + + const handleEdit = () => { + onOpenChange(false); + onEditContext(); + }; + + const handleProceed = () => { + onOpenChange(false); + onProceed(); + }; + + return ( + (next ? onOpenChange(true) : handleDismiss())}> + + +
+ +
+ {copy.title} + + {copy.description} + +
+ + {!previewFailed && ( +
+ + + +
+ )} + + {!hasContext &&

{t.contextReminder.hint}

} + + + + + +
+
+ ); +} + +const LINE_CLAMP = { 1: 'line-clamp-1', 2: 'line-clamp-2', 4: 'line-clamp-4' } as const; + +function PreviewRow({ + label, + value, + lines, + notSet, + loading, + highlight = false, +}: { + label: string; + value: string | undefined; + lines: keyof typeof LINE_CLAMP; + notSet: string; + loading: string; + /** The context is what this dialog is asking about, so it is the row that stands out. */ + highlight?: boolean; +}) { + const text = value?.trim(); + return ( +
+
{label}
+
+ {value === undefined ? loading : text || notSet} +
+
+ ); +} diff --git a/src/renderer/components/custom/mock-interview-setup-dialog.tsx b/src/renderer/components/custom/mock-interview-setup-dialog.tsx index f6e605e5..35fabba7 100644 --- a/src/renderer/components/custom/mock-interview-setup-dialog.tsx +++ b/src/renderer/components/custom/mock-interview-setup-dialog.tsx @@ -1,3 +1,4 @@ +import ContextReminderDialog from '@/components/custom/context-reminder-dialog'; import HeadphoneNoticeDialog from '@/components/custom/headphone-notice-dialog'; import { MockInterviewSetupFields } from '@/components/custom/mock-interview-setup-fields'; import { Button } from '@/components/ui/button'; @@ -41,6 +42,11 @@ export function MockInterviewSetupDialog({ starting, headphoneNoticeOpen, setHeadphoneNoticeOpen, + hasContext, + contextReminderOpen, + setContextReminderOpen, + confirmContext, + editContext, handleStartClick, startAfterNotice, } = form; @@ -54,7 +60,10 @@ export function MockInterviewSetupDialog({ Only `open` is computed; this component stays mounted either way, so the form state lives through the notice and comes back untouched if the candidate cancels out of it. */} - + {t.mock.setup.title} @@ -74,6 +83,19 @@ export function MockInterviewSetupDialog({ + {/* No onCancel: backing out returns to the setup form, which stays mounted underneath. */} + { + onOpenChange(false); + editContext(); + }} + /> + ('idle'); + const [currentPassword, setCurrentPassword] = useState(''); + const [code, setCode] = useState(''); + const [newPassword, setNewPassword] = useState(''); + const [confirmPassword, setConfirmPassword] = useState(''); + // `loading` is shared by every request this hook makes, so it cannot say which one is running. + const [sendingCode, setSendingCode] = useState(false); + + const close = () => { + setMode('idle'); + setCurrentPassword(''); + setCode(''); + setNewPassword(''); + setConfirmPassword(''); + setError(null); + }; + + // A stale server error ("current password is incorrect") stays on screen while the user is + // correcting the very field it is about, unless editing clears it. + const edit = (setter: (value: string) => void) => (value: string) => { + setter(value); + if (error) setError(null); + }; + + // Both new fields are masked, so a mismatch is the one condition the user cannot see for + // themselves. Held back until the confirm field has something in it. + const passwordsMismatch = confirmPassword !== '' && newPassword !== confirmPassword; + const newPasswordReady = newPassword !== '' && confirmPassword !== '' && !passwordsMismatch; + const canSubmit = + newPasswordReady && (mode === 'change' ? currentPassword !== '' : code.trim() !== ''); + + // A failure is reported by the inline `error`, which carries the server's reason; a toast + // beside it would repeat it. + const sendCode = async () => { + setError(null); + setSendingCode(true); + try { + return await forgotPassword(email); + } finally { + setSendingCode(false); + } + }; + + const startReset = async () => { + if (await sendCode()) { + setCurrentPassword(''); + setMode('reset'); + } + }; + + const submit = async (e: React.FormEvent) => { + e.preventDefault(); + if (!canSubmit || loading) return; + + if (mode === 'change') { + if (await changePassword(currentPassword, newPassword)) { + toast.success(t.changePassword.succeeded); + close(); + } + return; + } + + // A reset ends every session on the account, this one included, so it is a sign-out and is + // asked about like one - before the request, while declining still leaves everything intact. + if (!(await confirmDiscard('signout'))) return; + if (!(await resetPassword(email, code.trim(), newPassword))) return; + + toast.success(t.auth.reset.succeeded); + // The token is already dead on the server. Signing out here takes the user to the sign-in + // form now, rather than leaving them on a page whose next request fails as an expiry. + // Main clears the local session even when the backend call fails, so its error is moot. + try { + await logout(); + } catch (err) { + console.warn('Sign out after password reset failed:', err); + } + }; + + if (mode === 'idle') { + return ( +
+
+
+
+

{t.account.password.title}

+

{t.account.password.description}

+
+ +
+ ); + } + + return ( +
+
+
+
+
+

{t.changePassword.title}

+

+ {mode === 'change' ? t.changePassword.description : t.account.password.codeSent(email)} +

+
+
+ + {mode === 'change' ? ( +
+
+ + +
+ edit(setCurrentPassword)(e.target.value)} + placeholder={t.changePassword.currentPlaceholder} + maxLength={128} + disabled={loading} + /> +
+ ) : ( +
+
+ + +
+