PHP Livewire

Streamlining CV Generation with Smart Job Application Tracking

Introduction

In the landing project, we've recently rolled out a set of enhancements focused on improving the user's experience with CV generation and linking this process seamlessly to job application tracking. This update not only refines the editing workflow but also introduces a more robust and intelligent way to manage job applications created through our platform.

Our goal was to make the CV generation process more interactive and resilient, ensuring users can iterate on their CVs easily while the system intelligently tracks their application history without creating duplicate entries or failing critical operations.

Interactive CV Editing with contenteditable

Previously, editing a generated CV might have felt somewhat rigid. To make the process more fluid and user-friendly, we've replaced the traditional textarea editor with a contenteditable element. This allows users to directly edit their CV content within a rich editor interface on the frontend.

The changes are synced in real-time to the Livewire component's cvHtml property, ensuring that any edits are immediately reflected and can be saved. Alongside this, a new "Regenerar CV" button has been added, providing a clear and direct way for users to re-process their CV after making adjustments, triggering the generation logic with a simple wire:click="generate" directive.

<div wire:ignore>
    <div class="rich-editor" contenteditable="true"
         x-data="{ content: @entangle('cvHtml').defer }"
         x-init="$watch('content', value => $dispatch('input', value))"
         @input="content = $event.target.innerHTML">
        <!-- CV content goes here -->
    </div>
</div>
<button wire:click="generate" class="btn btn-primary mt-3">
    Regenerar CV
</button>

This snippet illustrates the core idea: using contenteditable with Livewire's @entangle and a simple wire:click for interaction. The wire:ignore directive is crucial to prevent Livewire from re-rendering the rich editor, allowing frontend libraries to manage its state, while still letting Livewire react to explicit input events.

Intelligent Job Application Tracking

A significant part of this update involves how we handle JobApplication records. When a user generates or regenerates a CV, the system now intelligently creates or updates an associated JobApplication record. This prevents duplicate entries while maintaining a clear history.

The JobApplication::firstOrCreate() method is utilized, using user_id and company_name as a unique key. If a user regenerates a CV for the same company, a new application record isn't created; instead, the existing one is retrieved. The application is also enriched with funnel_step (set to OptimizedCv) and funnel_data (containing cv_content, generated_cv_id, and compatibility_score), ensuring a clear link between the generated CV and the application's journey through our funnel.

use App\Models\JobApplication;
use App\Enums\JobApplicationFunnelStep;
use App\Enums\JobApplicationStatus;

// ... inside your generate method

try {
    $jobApplication = JobApplication::firstOrCreate(
        [
            'user_id' => auth()->id(),
            'company_name' => $this->companyName, // Example
        ],
        [
            'job_description' => $this->jobDescription, // Example
            'status' => JobApplicationStatus::Applied,
            'funnel_step' => JobApplicationFunnelStep::OptimizedCv,
            'funnel_data' => [
                'cv_content' => $this->cvHtml,
                'generated_cv_id' => $generatedCv->id,
                'compatibility_score' => $this->compatibilityScore,
            ],
        ]
    );
} catch (Throwable $e) {
    report($e);
    // Log error but allow CV generation to continue
}

This code block demonstrates the firstOrCreate pattern. It attempts to find an existing JobApplication for the user and company. If none is found, it creates a new one with the provided attributes, including the funnel details that link back to the generated CV data.

Resilient Error Handling

A critical improvement ensures that the core functionality of CV generation remains unaffected even if the job application tracking encounters an issue. The firstOrCreate() call for JobApplication is now encapsulated within its own try-catch block, specifically catching Throwable exceptions. If an error occurs during the creation or retrieval of the JobApplication, it is reported using report($e), but the user still receives their generated CV without encountering a server error.

This approach ensures a smooth user experience by isolating potential failures. The user always gets their CV, and developers are notified of any issues in the background. It's like having a safety net for a secondary process, preventing it from derailing the primary user flow.

Key Takeaways

These updates showcase how thoughtful UX design, combined with robust backend logic and error handling, can significantly enhance a core application feature. By adopting contenteditable for a more natural editing flow, implementing firstOrCreate for intelligent data management, and isolating error-prone operations, we deliver a more reliable and user-friendly experience. Always consider the potential failure points in non-critical paths and implement graceful degradation to protect the user's primary workflow.

Streamlining CV Generation with Smart Job Application Tracking
GERARDO RUIZ

GERARDO RUIZ

Author

Share: