@@ -5,33 +5,117 @@ struct WooShippingHazmatDetailView: View {
55
66 @Binding private var isHazardous : Bool
77
8+ @State private var detailURL : URL ?
9+
810 init ( isHazardous: Binding < Bool > ) {
911 self . _isHazardous = isHazardous
1012 }
1113
1214 var body : some View {
13- ScrollView {
14- VStack {
15- HStack {
16- Button ( Localization . cancel) {
17- dismiss ( )
15+ NavigationStack {
16+ ScrollView {
17+ VStack ( spacing: Constants . verticalSpacing) {
18+
19+ Text ( Localization . title)
20+ . secondaryTitleStyle ( )
21+ . bold ( )
22+ . frame ( maxWidth: . infinity, alignment: . leading)
23+
24+ Toggle ( isOn: $isHazardous) {
25+ Text ( Localization . toggleLabel)
26+ }
27+
28+ Button ( Localization . selectCategory) {
29+ // TODO: navigate to category list
1830 }
19- . padding ( . vertical)
31+ . buttonStyle ( PrimaryButtonStyle ( ) )
32+ . renderedIf ( isHazardous)
33+
34+ Divider ( )
35+
36+ Text ( Localization . detailLine1)
37+ . frame ( maxWidth: . infinity, alignment: . leading)
38+ Text ( detailLine2AttributedString)
39+ . frame ( maxWidth: . infinity, alignment: . leading)
40+ Text ( detailLine3AttributedString)
41+ . frame ( maxWidth: . infinity, alignment: . leading)
42+
2043 Spacer ( )
2144 }
45+ . environment ( \. openURL, OpenURLAction { url in
46+ detailURL = url
47+ return . handled
48+ } )
49+ . safariSheet ( url: $detailURL)
50+ . padding ( . horizontal)
51+ . toolbar {
52+ ToolbarItem ( placement: . cancellationAction) {
53+ Button ( Localization . cancel) {
54+ dismiss ( )
55+ }
56+ }
57+ }
58+ . toolbarBackground ( Color . clear, for: . navigationBar)
59+ }
60+ }
61+ }
62+ }
2263
23- Text ( Localization . title)
24- . secondaryTitleStyle ( )
25- . bold ( )
64+ private extension WooShippingHazmatDetailView {
65+ var detailLine2AttributedString : AttributedString {
66+ let content = String . localizedStringWithFormat ( Localization . detailLine2, Constants . hazmatURL, Localization . searchTool)
67+ var attributedText = AttributedString ( content)
68+ attributedText. font = . body
69+ attributedText. foregroundColor = Color ( . text)
2670
27- Spacer ( )
28- }
29- . padding ( . horizontal)
71+ if let range1 = attributedText. range ( of: Constants . hazmatURL) ,
72+ let url = URL ( string: Constants . hazmatURL) {
73+ var linkContainer = AttributeContainer ( )
74+ . link ( url)
75+ . foregroundColor ( Color . accentColor)
76+ linkContainer. underlineStyle = . single
77+ attributedText [ range1] . mergeAttributes ( linkContainer)
3078 }
79+
80+ if let range2 = attributedText. range ( of: Localization . searchTool) ,
81+ let url = URL ( string: Constants . searchToolURL) {
82+ var linkContainer = AttributeContainer ( )
83+ . link ( url)
84+ . foregroundColor ( Color . accentColor)
85+ linkContainer. underlineStyle = . single
86+ attributedText [ range2] . mergeAttributes ( linkContainer)
87+ }
88+ return attributedText
89+ }
90+
91+ var detailLine3AttributedString : AttributedString {
92+ let content = String . localizedStringWithFormat ( Localization . detailLine3, Constants . DHLExpressName)
93+
94+ var attributedText = AttributedString ( content)
95+ attributedText. font = . body
96+ attributedText. foregroundColor = Color ( . text)
97+
98+ if let range = attributedText. range ( of: Constants . DHLExpressName) ,
99+ let url = URL ( string: Constants . DHLExpressURL) {
100+ var linkContainer = AttributeContainer ( )
101+ . link ( url)
102+ . foregroundColor ( Color . accentColor)
103+ linkContainer. underlineStyle = . single
104+ attributedText [ range] . mergeAttributes ( linkContainer)
105+ }
106+
107+ return attributedText
31108 }
32109}
33110
34111private extension WooShippingHazmatDetailView {
112+ enum Constants {
113+ static let verticalSpacing : CGFloat = 16
114+ static let hazmatURL = " https://www.usps.com/hazmat "
115+ static let searchToolURL = " https://pe.usps.com/hazmat/index "
116+ static let DHLExpressName = " DHL Express "
117+ static let DHLExpressURL = " https://www.dhl.com/us-en/home/express.html "
118+ }
35119 enum Localization {
36120 static let title = NSLocalizedString (
37121 " wooShippingHazmatDetailView.title " ,
@@ -43,6 +127,41 @@ private extension WooShippingHazmatDetailView {
43127 value: " Cancel " ,
44128 comment: " Button to dismiss the HAZMAT detail view in the shipping label creation flow "
45129 )
130+ static let toggleLabel = NSLocalizedString (
131+ " wooShippingHazmatDetailView.switchLabel " ,
132+ value: " Contains hazardous materials " ,
133+ comment: " Label of the toggle on the HAZMAT detail view in the shipping label creation flow "
134+ )
135+ static let selectCategory = NSLocalizedString (
136+ " wooShippingHazmatDetailView.selectCategory " ,
137+ value: " Select Category " ,
138+ comment: " Button to select hazardous material category on the HAZMAT detail view in the shipping label creation flow "
139+ )
140+ static let detailLine1 = NSLocalizedString (
141+ " wooShippingHazmatDetailView.detailLine1 " ,
142+ value: " Potentially hazardous material includes items such as batteries, dry ice, " +
143+ " flammable liquids, aerosols, ammunition, fireworks, nail polish, perfume, paint, solvents, " +
144+ " and more. Hazardous items must ship in separate packages. " ,
145+ comment: " First line of the explanation on the HAZMAT detail view in the shipping label creation flow "
146+ )
147+ static let detailLine2 = NSLocalizedString (
148+ " wooShippingHazmatDetailView.detailLine2 " ,
149+ value: " Learn how to securely package, label, and ship HAZMAT through USPS® at " +
150+ " %1$@. Determine your product's mailability using the %2$@. " ,
151+ comment: " Second line of the explanation on the HAZMAT detail view in the shipping label creation flow. " +
152+ " The placeholders are links to detail pages for HAZMAT. "
153+ )
154+ static let searchTool = NSLocalizedString (
155+ " wooShippingHazmatDetailView.searchTool " ,
156+ value: " USPS HAZMAT Search Tool " ,
157+ comment: " Name of the search tool linked on the HAZMAT detail view in the shipping label creation flow. "
158+ )
159+ static let detailLine3 = NSLocalizedString (
160+ " wooShippingHazmatDetailView.detailLine3 " ,
161+ value: " WooCommerce Shipping does not currently support HAZMAT shipments through %1$@. " ,
162+ comment: " Third line of the explanation on the HAZMAT detail view in the shipping label creation flow. " +
163+ " The placeholder is DHL Express. "
164+ )
46165 }
47166}
48167
0 commit comments