budget/app/views/expenses/_form.html.erb

103 lines
5.8 KiB
Text

<%= form_with(model: expense, class: "space-y-6") do |form| %>
<% if expense.errors.any? %>
<div id="error_explanation" class="bg-red-50 border border-red-200 text-red-600 px-4 py-3 rounded-lg">
<div class="flex">
<div class="flex-shrink-0">
<svg class="h-5 w-5 text-red-400" fill="currentColor" viewBox="0 0 20 20">
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z" clip-rule="evenodd"/>
</svg>
</div>
<div class="ml-3">
<h3 class="text-sm font-medium"><%= pluralize(expense.errors.count, "error") %> prohibited this expense from being saved:</h3>
<div class="mt-2 text-sm">
<ul class="list-disc list-inside space-y-1">
<% expense.errors.each do |error| %>
<li><%= error.full_message %></li>
<% end %>
</ul>
</div>
</div>
</div>
</div>
<% end %>
<div class="bg-white rounded-lg shadow-sm border border-gray-200 p-4 sm:p-6 lg:p-8">
<h3 class="text-lg font-medium text-gray-900 mb-6">Expense Information</h3>
<div class="grid grid-cols-1 gap-6 lg:grid-cols-2">
<div class="lg:col-span-2">
<%= form.label :description, class: "block text-sm font-medium text-gray-700" %>
<%= form.text_field :description, class: "mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-1 focus:ring-blue-500 focus:border-blue-500 sm:text-sm", placeholder: "e.g., Netflix subscription" %>
<p class="mt-1 text-sm text-gray-500">A brief description of the expense</p>
</div>
<div>
<%= form.label :payment, class: "block text-sm font-medium text-gray-700" %>
<div class="mt-1 relative rounded-md shadow-sm">
<div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
<span class="text-gray-500 sm:text-sm">$</span>
</div>
<%= form.text_field :payment, class: "pl-7 pr-3 py-2 block w-full border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-1 focus:ring-blue-500 focus:border-blue-500 sm:text-sm", placeholder: "0.00" %>
</div>
<p class="mt-1 text-sm text-gray-500">The payment amount for this billing period</p>
</div>
<div>
<%= form.label :period, class: "block text-sm font-medium text-gray-700" %>
<%=
form.select :period,
options_for_select(expense_periods, expense.period),
{},
class: "mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-1 focus:ring-blue-500 focus:border-blue-500 sm:text-sm"
%>
<p class="mt-1 text-sm text-gray-500">How often this expense is billed</p>
</div>
</div>
</div>
<div class="bg-white rounded-lg shadow-sm border border-gray-200 p-4 sm:p-6 lg:p-8">
<h3 class="text-lg font-medium text-gray-900 mb-6">Payment Details</h3>
<div class="space-y-4">
<div class="flex items-center justify-between">
<div class="flex-grow">
<label for="expense_credit_card" class="text-sm font-medium text-gray-700">Credit Card Payment</label>
<p class="text-sm text-gray-500">This expense is paid by credit card</p>
</div>
<div class="flex-shrink-0 ml-4">
<%= form.check_box :credit_card, class: "toggle-checkbox sr-only" %>
<label for="expense_credit_card" class="toggle-label relative inline-flex h-6 w-11 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 bg-gray-200">
<span class="toggle-switch pointer-events-none inline-block h-5 w-5 transform rounded-full bg-white shadow ring-0 transition duration-200 ease-in-out translate-x-0"></span>
</label>
</div>
</div>
<div class="flex items-center justify-between">
<div class="flex-grow">
<label for="expense_estimated" class="text-sm font-medium text-gray-700">Estimated Amount</label>
<p class="text-sm text-gray-500">This amount is an estimate</p>
</div>
<div class="flex-shrink-0 ml-4">
<%= form.check_box :estimated, class: "toggle-checkbox sr-only" %>
<label for="expense_estimated" class="toggle-label relative inline-flex h-6 w-11 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 bg-gray-200">
<span class="toggle-switch pointer-events-none inline-block h-5 w-5 transform rounded-full bg-white shadow ring-0 transition duration-200 ease-in-out translate-x-0"></span>
</label>
</div>
</div>
</div>
</div>
<style>
.toggle-checkbox:checked + .toggle-label {
background-color: rgb(59, 130, 246);
}
.toggle-checkbox:checked + .toggle-label .toggle-switch {
transform: translateX(1.25rem);
}
</style>
<div class="flex justify-end gap-3">
<%= link_to "Cancel", expenses_path, class: "inline-flex items-center px-4 py-2 border border-gray-300 rounded-md shadow-sm text-sm font-medium text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-gray-500" %>
<%= form.submit class: "inline-flex items-center px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-blue-600 hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 cursor-pointer" %>
</div>
<% end %>