feat: полноценное Pulse приложение с TabBar
- Auth: переключено на Pulse API (api.digital-home.site) вместо health - TabBar: Главная, Задачи, Привычки, Здоровье, Финансы - Models: TaskModels, HabitModels, FinanceModels, обновлённые AuthModels - Services: APIService (Pulse API), HealthAPIService (health отдельно) - Dashboard: обзор дня с задачами, привычками, readiness, балансом - Tasks: список, фильтр, создание, выполнение, удаление - Habits: список с прогресс-баром, отметка выполнения, стрики - Health: бывший DashboardView, HealthKit sync через health API key - Finance: баланс, список транзакций, добавление расхода/дохода - Health данные через x-api-key вместо JWT токена health сервиса
This commit is contained in:
82
PulseHealth/Views/Finance/AddTransactionView.swift
Normal file
82
PulseHealth/Views/Finance/AddTransactionView.swift
Normal file
@@ -0,0 +1,82 @@
|
||||
import SwiftUI
|
||||
|
||||
struct AddTransactionView: View {
|
||||
@Binding var isPresented: Bool
|
||||
@EnvironmentObject var authManager: AuthManager
|
||||
let categories: [FinanceCategory]
|
||||
let onAdded: () async -> Void
|
||||
|
||||
@State private var amount = ""
|
||||
@State private var description = ""
|
||||
@State private var type = "expense"
|
||||
@State private var selectedCategoryId: Int? = nil
|
||||
@State private var isLoading = false
|
||||
|
||||
var filteredCategories: [FinanceCategory] { categories.filter { $0.type == type } }
|
||||
|
||||
var body: some View {
|
||||
NavigationView {
|
||||
ZStack {
|
||||
Color(hex: "0a0a1a").ignoresSafeArea()
|
||||
VStack(spacing: 16) {
|
||||
Picker("", selection: $type) {
|
||||
Text("Расход").tag("expense")
|
||||
Text("Доход").tag("income")
|
||||
}
|
||||
.pickerStyle(.segmented)
|
||||
|
||||
TextField("Сумма", text: $amount)
|
||||
.keyboardType(.decimalPad)
|
||||
.padding().background(Color.white.opacity(0.08)).cornerRadius(12).foregroundColor(.white)
|
||||
|
||||
TextField("Описание", text: $description)
|
||||
.padding().background(Color.white.opacity(0.08)).cornerRadius(12).foregroundColor(.white)
|
||||
|
||||
if !filteredCategories.isEmpty {
|
||||
ScrollView(.horizontal, showsIndicators: false) {
|
||||
HStack(spacing: 8) {
|
||||
ForEach(filteredCategories) { cat in
|
||||
Button(action: { selectedCategoryId = cat.id }) {
|
||||
HStack(spacing: 4) {
|
||||
Text(cat.icon ?? "").font(.caption)
|
||||
Text(cat.name).font(.caption)
|
||||
}
|
||||
.padding(.horizontal, 12).padding(.vertical, 6)
|
||||
.background(RoundedRectangle(cornerRadius: 20)
|
||||
.fill(selectedCategoryId == cat.id ? Color(hex: "00d4aa").opacity(0.3) : Color.white.opacity(0.08)))
|
||||
.foregroundColor(selectedCategoryId == cat.id ? Color(hex: "00d4aa") : .white)
|
||||
}
|
||||
}
|
||||
}.padding(.horizontal)
|
||||
}
|
||||
}
|
||||
Spacer()
|
||||
}.padding()
|
||||
}
|
||||
.navigationTitle("Новая операция")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .cancellationAction) { Button("Отмена") { isPresented = false } }
|
||||
ToolbarItem(placement: .confirmationAction) {
|
||||
Button("Добавить") {
|
||||
guard let a = Double(amount.replacingOccurrences(of: ",", with: ".")) else { return }
|
||||
isLoading = true
|
||||
Task {
|
||||
let req = CreateTransactionRequest(
|
||||
amount: a,
|
||||
categoryId: selectedCategoryId,
|
||||
description: description.isEmpty ? nil : description,
|
||||
type: type
|
||||
)
|
||||
try? await APIService.shared.createTransaction(token: authManager.token, request: req)
|
||||
await onAdded()
|
||||
await MainActor.run { isPresented = false }
|
||||
}
|
||||
}
|
||||
.disabled(amount.isEmpty || isLoading)
|
||||
}
|
||||
}
|
||||
.preferredColorScheme(.dark)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user