API Integration: - Fix logHabit: send "date" instead of "completed_at" - Fix FinanceCategory: "icon" → "emoji" to match API - Fix task priorities: remove level 4, keep 1-3 matching API - Fix habit frequencies: map monthly/interval → "custom" for API - Add token refresh (401 → auto retry with new token) - Add proper error handling (remove try? in save functions, show errors in UI) - Add date field to savings transactions - Add MonthlyPaymentDetail and OverduePayment models - Fix habit completedToday: compute on client from logs (API doesn't return it) - Filter habits by day of week on client (daily/weekly/monthly/interval) Design System (glassmorphism): - New DesignSystem.swift: Theme colors, GlassCard modifier, GlowIcon, GlowStatCard - Custom tab bar with per-tab glow colors (VStack layout, not ZStack overlay) - Deep dark background #06060f across all views - Glass cards with gradient fill + stroke throughout app - App icon: glassmorphism style with teal glow Health Dashboard: - Compact ReadinessBanner with recommendation text - 8 metric tiles: sleep, HR, HRV, steps, SpO2, respiratory rate, energy, distance - Each tile with status indicator (good/ok/bad) and hint text - Heart rate card (min/avg/max) - Weekly trends card (averages) - Recovery score (weighted: 40% sleep, 35% HRV, 25% RHR) - Tips card with actionable recommendations - Sleep detail view with hypnogram (step chart of phases) - Sleep segments timeline from HealthKit (deep/rem/core/awake with exact times) - Line chart replacing bar chart for weekly data - Collect respiratory_rate and sleep phases with timestamps from HealthKit - Background sync every ~30min via BGProcessingTask Notifications: - NotificationService for local push notifications - Morning/evening reminders with native DatePicker (wheel) - Payment reminders: 5 days, 1 day, and day-of for recurring savings - Notification settings in Settings tab UI Fixes: - Fix color picker overflow: HStack → LazyVGrid 5 columns - Fix sheet headers: shorter text, proper padding - Fix task/habit toggle: separate tap zones (checkbox vs edit) - Fix deprecated onChange syntax for iOS 17+ - Savings overview: real monthly payments and detailed overdues from API - Settings: timezone as Menu picker, removed Telegram/server notifications sections - All sheets use .presentationDetents([.large]) Config: - project.yml: real DEVELOPMENT_TEAM, HealthKit + BackgroundModes capabilities - Info.plist: BGTaskScheduler + UIBackgroundModes - Assets.xcassets with AppIcon - CLAUDE.md project documentation Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
164 lines
8.3 KiB
Swift
164 lines
8.3 KiB
Swift
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 date = Date()
|
||
@State private var isLoading = false
|
||
@State private var errorMessage: String?
|
||
|
||
var filteredCategories: [FinanceCategory] { categories.filter { $0.type == type } }
|
||
var isExpense: Bool { type == "expense" }
|
||
|
||
var body: some View {
|
||
ZStack {
|
||
Color(hex: "06060f").ignoresSafeArea()
|
||
|
||
VStack(spacing: 0) {
|
||
// Handle
|
||
RoundedRectangle(cornerRadius: 3)
|
||
.fill(Color.white.opacity(0.2))
|
||
.frame(width: 40, height: 4)
|
||
.padding(.top, 12)
|
||
|
||
// Header
|
||
HStack {
|
||
Button("Отмена") { isPresented = false }.foregroundColor(Color(hex: "8888aa"))
|
||
Spacer()
|
||
Text("Новая операция").font(.headline).foregroundColor(.white)
|
||
Spacer()
|
||
Button(action: save) {
|
||
if isLoading { ProgressView().tint(Color(hex: "00d4aa")).scaleEffect(0.8) }
|
||
else { Text("Добавить").foregroundColor(amount.isEmpty ? Color(hex: "8888aa") : Color(hex: "00d4aa")).fontWeight(.semibold) }
|
||
}.disabled(amount.isEmpty || isLoading)
|
||
}
|
||
.padding(.horizontal, 20).padding(.vertical, 16)
|
||
|
||
Divider().background(Color.white.opacity(0.1))
|
||
|
||
ScrollView {
|
||
VStack(spacing: 20) {
|
||
// Type toggle
|
||
HStack(spacing: 0) {
|
||
Button(action: { type = "expense" }) {
|
||
Text("Расход")
|
||
.font(.callout.bold())
|
||
.foregroundColor(isExpense ? .black : Color(hex: "ff4757"))
|
||
.frame(maxWidth: .infinity).padding(.vertical, 12)
|
||
.background(isExpense ? Color(hex: "ff4757") : Color.clear)
|
||
}
|
||
Button(action: { type = "income" }) {
|
||
Text("Доход")
|
||
.font(.callout.bold())
|
||
.foregroundColor(!isExpense ? .black : Color(hex: "00d4aa"))
|
||
.frame(maxWidth: .infinity).padding(.vertical, 12)
|
||
.background(!isExpense ? Color(hex: "00d4aa") : Color.clear)
|
||
}
|
||
}
|
||
.background(Color.white.opacity(0.07))
|
||
.cornerRadius(12)
|
||
|
||
// Amount
|
||
VStack(spacing: 8) {
|
||
Text(isExpense ? "Сумма расхода" : "Сумма дохода")
|
||
.font(.caption).foregroundColor(Color(hex: "8888aa"))
|
||
HStack {
|
||
Text(isExpense ? "−" : "+")
|
||
.font(.title.bold())
|
||
.foregroundColor(isExpense ? Color(hex: "ff4757") : Color(hex: "00d4aa"))
|
||
TextField("0", text: $amount)
|
||
.keyboardType(.decimalPad)
|
||
.font(.system(size: 36, weight: .bold))
|
||
.foregroundColor(.white)
|
||
.multilineTextAlignment(.center)
|
||
Text("₽")
|
||
.font(.title.bold())
|
||
.foregroundColor(Color(hex: "8888aa"))
|
||
}
|
||
.padding(20)
|
||
.background(RoundedRectangle(cornerRadius: 16).fill(Color.white.opacity(0.07)))
|
||
}
|
||
|
||
// Description
|
||
VStack(alignment: .leading, spacing: 8) {
|
||
Label("Описание", systemImage: "text.alignleft").font(.caption).foregroundColor(Color(hex: "8888aa"))
|
||
TextField("Комментарий...", text: $description)
|
||
.foregroundColor(.white).padding(14)
|
||
.background(RoundedRectangle(cornerRadius: 12).fill(Color.white.opacity(0.07)))
|
||
}
|
||
|
||
// Date
|
||
VStack(alignment: .leading, spacing: 8) {
|
||
Label("Дата", systemImage: "calendar").font(.caption).foregroundColor(Color(hex: "8888aa"))
|
||
DatePicker("", selection: $date, displayedComponents: .date)
|
||
.labelsHidden()
|
||
.colorInvert()
|
||
.colorMultiply(Color(hex: "0D9488"))
|
||
}
|
||
|
||
// Categories
|
||
if !filteredCategories.isEmpty {
|
||
VStack(alignment: .leading, spacing: 8) {
|
||
Label("Категория", systemImage: "tag.fill").font(.caption).foregroundColor(Color(hex: "8888aa"))
|
||
LazyVGrid(columns: [GridItem(.adaptive(minimum: 100))], spacing: 8) {
|
||
ForEach(filteredCategories) { cat in
|
||
Button(action: { selectedCategoryId = selectedCategoryId == cat.id ? nil : cat.id }) {
|
||
HStack(spacing: 6) {
|
||
Text(cat.emoji ?? "").font(.callout)
|
||
Text(cat.name).font(.caption).lineLimit(1)
|
||
}
|
||
.foregroundColor(selectedCategoryId == cat.id ? .black : .white)
|
||
.padding(.horizontal, 10).padding(.vertical, 8)
|
||
.frame(maxWidth: .infinity)
|
||
.background(
|
||
RoundedRectangle(cornerRadius: 10)
|
||
.fill(selectedCategoryId == cat.id ? Color(hex: "00d4aa") : Color.white.opacity(0.07))
|
||
)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if let err = errorMessage {
|
||
Text(err)
|
||
.font(.caption).foregroundColor(Color(hex: "ff4757"))
|
||
.padding(10)
|
||
.frame(maxWidth: .infinity)
|
||
.background(RoundedRectangle(cornerRadius: 10).fill(Color(hex: "ff4757").opacity(0.1)))
|
||
}
|
||
}
|
||
.padding(20)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
func save() {
|
||
guard let a = Double(amount.replacingOccurrences(of: ",", with: ".")) else { return }
|
||
isLoading = true
|
||
errorMessage = nil
|
||
let df = DateFormatter(); df.dateFormat = "yyyy-MM-dd"
|
||
let dateStr = df.string(from: date)
|
||
Task {
|
||
do {
|
||
let req = CreateTransactionRequest(amount: a, categoryId: selectedCategoryId, description: description.isEmpty ? nil : description, type: type, date: dateStr)
|
||
try await APIService.shared.createTransaction(token: authManager.token, request: req)
|
||
await onAdded()
|
||
await MainActor.run { isPresented = false }
|
||
} catch {
|
||
await MainActor.run {
|
||
errorMessage = error.localizedDescription
|
||
isLoading = false
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|