Skip to content

Self-hosted project management for devs and their clients: tickets, time tracking, docs and meetings, with an AI assistant that cites its sources. AGPL-3.0.

10.4 KB
Raw Blame
<div class="max-w-4xl mx-auto py-6 sm:px-6 lg:px-8">
  <div class="px-4 py-6 sm:px-0">
    <div class="mb-6">
      <h1 class="text-3xl font-bold text-gray-900"><%= t('views.admin.users.new.title') %></h1>
      <p class="mt-2 text-gray-600"><%= t('views.admin.users.new.subtitle') %></p>
    </div>

    <div class="bg-white border-2 border-black rounded-lg shadow-[2px_2px_0_0_#000000]" data-controller="admin-user-form">
      <%= form_with(model: [@user], url: admin_users_path, method: :post, local: true, class: "space-y-6") do |f| %>
        <%# === User Information Section === %>
        <div class="px-6 py-6 border-b-2 border-black">
          <h2 class="text-lg font-medium text-gray-900 mb-4">
            <i class="bi bi-person-circle text-blue-500 mr-2"></i>
            <%= t('views.admin.users.new.user_information') %>
          </h2>

          <div class="grid grid-cols-1 gap-6 sm:grid-cols-2">
            <div>
              <%= f.label :first_name, t('views.admin.users.new.first_name'), class: "block text-sm font-medium text-gray-700 mb-2" %>
              <%= f.text_field :first_name,
                    class: "mt-1 block w-full rounded-md border-2 border-black shadow-sm focus:border-blue-500 focus:ring-blue-500",
                    placeholder: "Max" %>
              <% if @user.errors[:first_name].any? %>
                <p class="mt-1 text-sm text-red-600"><%= @user.errors[:first_name].first %></p>
              <% end %>
            </div>

            <div>
              <%= f.label :last_name, t('views.admin.users.new.last_name'), class: "block text-sm font-medium text-gray-700 mb-2" %>
              <%= f.text_field :last_name,
                    class: "mt-1 block w-full rounded-md border-2 border-black shadow-sm focus:border-blue-500 focus:ring-blue-500",
                    placeholder: "Mustermann" %>
              <% if @user.errors[:last_name].any? %>
                <p class="mt-1 text-sm text-red-600"><%= @user.errors[:last_name].first %></p>
              <% end %>
            </div>

            <div class="sm:col-span-2">
              <%= f.label :email, t('views.admin.users.new.email'), class: "block text-sm font-medium text-gray-700 mb-2" %>
              <%= f.email_field :email,
                    class: "mt-1 block w-full rounded-md border-2 border-black shadow-sm focus:border-blue-500 focus:ring-blue-500",
                    placeholder: "[email protected]",
                    required: true %>
              <% if @user.errors[:email].any? %>
                <p class="mt-1 text-sm text-red-600"><%= @user.errors[:email].first %></p>
              <% end %>
              <p class="mt-1 text-sm text-gray-500">
                <%= t('views.admin.users.new.temp_password_hint') %>
              </p>
            </div>

            <div class="sm:col-span-2">
              <div class="flex items-center">
                <%= f.check_box :active,
                      checked: true,
                      class: "h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded" %>
                <%= f.label :active, t('views.admin.users.new.user_is_active'), class: "ml-2 block text-sm text-gray-900" %>
              </div>
              <p class="mt-1 text-sm text-gray-500">
                <%= t('views.admin.users.new.active_hint') %>
              </p>
            </div>
          </div>
        </div>

        <%# === Organisation Section with Radio Toggle === %>
        <div class="px-6 py-6">
          <h2 class="text-lg font-medium text-gray-900 mb-4">
            <i class="bi bi-building text-green-500 mr-2"></i>
            <%= t('views.admin.users.new.organisation') %>
          </h2>

          <%# Radio Toggle %>
          <div class="flex gap-4 mb-6">
            <label class="inline-flex items-center cursor-pointer px-4 py-2 border-2 border-black rounded-md has-[:checked]:bg-blue-100 has-[:checked]:border-blue-600 has-[:checked]:shadow-[2px_2px_0_0_#000000] transition-all">
              <input type="radio" name="organisation_mode" value="new" checked
                     class="mr-2 text-blue-600 focus:ring-blue-500"
                     data-action="change->admin-user-form#toggleMode">
              <i class="bi bi-plus-circle mr-1"></i>
              <%= t('views.admin.users.new.create_new_organisation') %>
            </label>

            <label class="inline-flex items-center cursor-pointer px-4 py-2 border-2 border-black rounded-md has-[:checked]:bg-blue-100 has-[:checked]:border-blue-600 has-[:checked]:shadow-[2px_2px_0_0_#000000] transition-all">
              <input type="radio" name="organisation_mode" value="existing"
                     class="mr-2 text-blue-600 focus:ring-blue-500"
                     data-action="change->admin-user-form#toggleMode">
              <i class="bi bi-building-add mr-1"></i>
              <%= t('views.admin.users.new.add_to_existing_organisation') %>
            </label>
          </div>

          <%# === New Organisation Fields === %>
          <div data-admin-user-form-target="newOrgFields">
            <%= fields_for :organisation, @organisation do |org_f| %>
              <div class="grid grid-cols-1 gap-6 sm:grid-cols-2">
                <div class="sm:col-span-2">
                  <%= org_f.label :name, t('views.admin.users.new.organisation_name'), class: "block text-sm font-medium text-gray-700 mb-2" %>
                  <%= org_f.text_field :name,
                        class: "mt-1 block w-full rounded-md border-2 border-black shadow-sm focus:border-blue-500 focus:ring-blue-500",
                        placeholder: "Muster GmbH",
                        required: true %>
                  <% if @organisation.errors[:name].any? %>
                    <p class="mt-1 text-sm text-red-600"><%= @organisation.errors[:name].first %></p>
                  <% end %>
                </div>

                <div>
                  <%= org_f.label :subdomain, t('views.admin.users.new.subdomain_optional'), class: "block text-sm font-medium text-gray-700 mb-2" %>
                  <%= org_f.text_field :subdomain,
                        class: "mt-1 block w-full rounded-md border-2 border-black shadow-sm focus:border-blue-500 focus:ring-blue-500",
                        placeholder: "muster-gmbh" %>
                  <% if @organisation.errors[:subdomain].any? %>
                    <p class="mt-1 text-sm text-red-600"><%= @organisation.errors[:subdomain].first %></p>
                  <% end %>
                  <p class="mt-1 text-sm text-gray-500">
                    <%= t('views.admin.users.new.subdomain_hint') %>
                  </p>
                </div>

                <div>
                  <%= org_f.label :domain, t('views.admin.users.new.custom_domain_optional'), class: "block text-sm font-medium text-gray-700 mb-2" %>
                  <%= org_f.text_field :domain,
                        class: "mt-1 block w-full rounded-md border-2 border-black shadow-sm focus:border-blue-500 focus:ring-blue-500",
                        placeholder: "lalabase.muster-gmbh.de" %>
                  <% if @organisation.errors[:domain].any? %>
                    <p class="mt-1 text-sm text-red-600"><%= @organisation.errors[:domain].first %></p>
                  <% end %>
                  <p class="mt-1 text-sm text-gray-500">
                    <%= t('views.admin.users.new.custom_domain_hint') %>
                  </p>
                </div>
              </div>
            <% end %>
          </div>

          <%# === Existing Organisation Fields === %>
          <div data-admin-user-form-target="existingOrgFields" class="hidden">
            <div class="grid grid-cols-1 gap-6">
              <div>
                <label for="existing_organisation_id" class="block text-sm font-medium text-gray-700 mb-2"><%= t('views.admin.users.new.organisation') %></label>
                <select name="existing_organisation_id" id="existing_organisation_id"
                        data-admin-user-form-target="orgSelect"
                        data-action="change->admin-user-form#loadRoles"
                        class="mt-1 block w-full rounded-md border-2 border-black shadow-sm focus:border-blue-500 focus:ring-blue-500"
                        disabled>
                  <option value=""><%= t('views.admin.users.new.select_organisation') %></option>
                  <% @organisations.each do |org| %>
                    <option value="<%= org.id %>"><%= org.name %></option>
                  <% end %>
                </select>
              </div>

              <turbo-frame id="role_select" data-admin-user-form-target="roleFrame">
                <p class="text-sm text-gray-500"><%= t('views.admin.users.new.select_organisation_first') %></p>
              </turbo-frame>
            </div>
          </div>
        </div>

        <%# === Submit Section === %>
        <div class="px-6 py-4 bg-gray-50 border-t-2 border-black flex justify-between items-center">
          <%= link_to admin_users_path,
                class: "inline-flex items-center px-4 py-2 border-2 border-black shadow-sm text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50 hover:shadow-[2px_2px_0_0_#000000] transition-shadow" do %>
            <i class="bi bi-arrow-left mr-2"></i>
            <%= t('views.admin.users.new.back_to_overview') %>
          <% end %>

          <%= f.submit t('views.admin.users.new.create_user'),
                class: "inline-flex items-center px-4 py-2 border-2 border-black text-sm font-bold rounded-md shadow-[2px_2px_0_0_#000000] text-white bg-blue-600 hover:bg-blue-700 hover:shadow-[4px_4px_0_0_#000000] transition-shadow cursor-pointer" %>
        </div>
      <% end %>
    </div>

    <div class="mt-6 bg-blue-50 border-2 border-blue-300 rounded-lg p-4 shadow-[2px_2px_0_0_#93c5fd]">
      <div class="flex">
        <div class="flex-shrink-0">
          <i class="bi bi-info-circle text-blue-400"></i>
        </div>
        <div class="ml-3">
          <h3 class="text-sm font-medium text-blue-800"><%= t('views.admin.users.new.important_info_title') %></h3>
          <div class="mt-2 text-sm text-blue-700">
            <ul class="list-disc pl-5 space-y-1">
              <li><%= t('views.admin.users.new.important_info_new_org_html') %></li>
              <li><%= t('views.admin.users.new.important_info_existing_org_html') %></li>
              <li><%= t('views.admin.users.new.important_info_temp_password') %></li>
              <li><%= t('views.admin.users.new.important_info_change_password') %></li>
            </ul>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>