-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathShopCreateView.swift
More file actions
76 lines (67 loc) · 1.73 KB
/
Copy pathShopCreateView.swift
File metadata and controls
76 lines (67 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//
// ShopCreateView.swift
// NativeAppTemplate
//
// Created by Daisuke Adachi on 2022/06/07.
//
import SwiftUI
struct ShopCreateView: View {
@Environment(\.dismiss) private var dismiss
@State private var viewModel: ShopCreateViewModel
init(viewModel: ShopCreateViewModel) {
self._viewModel = State(wrappedValue: viewModel)
}
var body: some View {
contentView
.onChange(of: viewModel.shouldDismiss) {
if viewModel.shouldDismiss {
dismiss()
}
}
}
@ViewBuilder
private var contentView: some View {
if viewModel.isCreating {
LoadingView()
} else {
shopCreateForm
}
}
private var shopCreateForm: some View {
NavigationStack {
Form {
Section {
TextField(String.name, text: $viewModel.name)
} footer: {
Text(String.shopNameIsRequired)
.foregroundStyle(viewModel.hasInvalidData ? .red : .clear)
}
Section {
TextField(String.descriptionString, text: $viewModel.description, axis: .vertical)
.lineLimit(10, reservesSpace: true)
}
Section {
Picker(String.timeZone, selection: $viewModel.selectedTimeZone) {
ForEach(timeZones.keys, id: \.self) { key in
Text(timeZones[key]!).tag(key)
}
}
}
}
.navigationTitle(String.addShop)
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
Button(String.save) {
viewModel.createShop()
}
.disabled(viewModel.hasInvalidData)
}
ToolbarItem(placement: .navigationBarLeading) {
Button(String.cancel) {
dismiss()
}
}
}
}
}
}