Skip to content

Role (Função) dropdown does not save selection — RoleSerializer missing 'key' field #63

@ErissonLucas

Description

@ErissonLucas

Bug Description

When creating or editing an attendant in the CRM, the "Função" (Role) dropdown appears to work (expands and shows options) but does not retain the selected value — the field remains empty after clicking an option.

Root Cause

The RoleSerializer in the auth service does not include the key field in its JSON output.

The frontend (React) uses Radix UI's <Select> component and maps roles like this (from the compiled bundle):

o.map(x => <SelectItem value={x.key}>{x.name}</SelectItem>)

Since x.key is undefined (not returned by the API), all <SelectItem> elements have value={undefined}, and the Radix Select component cannot match or store the selection.

Affected File

app/serializers/role_serializer.rb — both full and basic methods return role data without the key field:

# Current (broken)
def full(role)
  {
    id: role.id,
    name: role.name,
    description: role.description,
    permissions: role.permissions_by_resource,
    # ...
  }
end

def basic(role)
  { id: role.id, name: role.name, description: role.description }
end

Fix

Add key: role.key to both serializer methods:

def full(role)
  {
    id: role.id,
    key: role.key,      # <-- ADD THIS
    name: role.name,
    description: role.description,
    permissions: role.permissions_by_resource,
    created_at: role.created_at,
    updated_at: role.updated_at
  }
end

def basic(role)
  { id: role.id, key: role.key, name: role.name, description: role.description }
  #                  ^^^^^^^^^^
end

Steps to Reproduce

  1. Log in as admin in Evo CRM
  2. Go to AtendentesNovo Atendente
  3. Click the "Função" (Role) dropdown
  4. Select any option (e.g., "Atendente")
  5. The dropdown closes but shows empty — role is not selected

Impact

  • Admins cannot assign roles when creating attendants
  • If role is required, form submission fails with a validation error

Environment

  • Deployment: Docker Swarm / Portainer
  • Frontend: React + Radix UI + Vite
  • Backend: Rails 7.1
  • evo-crm-community:latest

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions