@abgov/nx-adsp 5.8.0 → 5.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abgov/nx-adsp",
3
- "version": "5.8.0",
3
+ "version": "5.8.2",
4
4
  "license": "Apache-2.0",
5
5
  "main": "src/index.js",
6
6
  "description": "Government of Alberta - Nx plugin for ADSP apps.",
@@ -1,4 +1,6 @@
1
1
  .form {
2
+ max-width: 800px;
3
+
2
4
  > fieldset {
3
5
  display: none;
4
6
  }
@@ -49,6 +49,7 @@ export interface <%= className %>State {
49
49
  saving: boolean;
50
50
  submitting: boolean;
51
51
  };
52
+ errorMessage: string;
52
53
  }
53
54
 
54
55
  function areSectionsComplete(
@@ -75,7 +76,7 @@ function areSectionsComplete(
75
76
  let completion: SectionCompletion = null;
76
77
  if (!hasError && hasValues.length === requiredValues.length) {
77
78
  completion = 'complete';
78
- } else {
79
+ } else if (hasValues.length > 0) {
79
80
  // This means partial completion.
80
81
  completion = 'incomplete';
81
82
  }
@@ -172,6 +173,11 @@ const formSaved = createAction(
172
173
  (values: <%= className %>) => ({ payload: values })
173
174
  );
174
175
 
176
+ const formSaveRejected = createAction(
177
+ '<%= propertyName %>/save-rejected',
178
+ (message: string) => ({ payload: message })
179
+ );
180
+
175
181
  const queueSaveForm = createAsyncThunk(
176
182
  '<%= propertyName %>/queue-save',
177
183
  debounce(
@@ -181,13 +187,22 @@ const queueSaveForm = createAsyncThunk(
181
187
  const { formId }: <%= className %>State =
182
188
  state[<%= constantName %>_FEATURE_KEY];
183
189
 
184
- await axios.put(
185
- `${FORM_SERVICE_URL}/form/v1/forms/${formId}/data`,
186
- { data: values },
187
- { headers: { Authorization: `Bearer ${user.access_token}` } }
188
- );
189
-
190
- dispatch(formSaved(values));
190
+ try {
191
+ await axios.put(
192
+ `${FORM_SERVICE_URL}/form/v1/forms/${formId}/data`,
193
+ { data: values },
194
+ { headers: { Authorization: `Bearer ${user.access_token}` } }
195
+ );
196
+
197
+ dispatch(formSaved(values));
198
+ } catch (err) {
199
+ let message = 'Unexpected error saving form.';
200
+ if (axios.isAxiosError(err) && err.response?.status === 400) {
201
+ message = err.response?.data?.errorMessage;
202
+ }
203
+
204
+ dispatch(formSaveRejected(message));
205
+ }
191
206
  },
192
207
  2000,
193
208
  { trailing: true, leading: false }
@@ -256,6 +271,7 @@ export const initial<%= className %>State: <%= className %>State = {
256
271
  saving: false,
257
272
  submitting: false,
258
273
  },
274
+ errorMessage: null,
259
275
  };
260
276
 
261
277
  export const <%= propertyName %>Slice = createSlice({
@@ -292,6 +308,10 @@ export const <%= propertyName %>Slice = createSlice({
292
308
  .addCase(formSaved, (state) => {
293
309
  state.busy.saving = false;
294
310
  })
311
+ .addCase(formSaveRejected, (state, action) => {
312
+ state.busy.saving = false;
313
+ state.errorMessage = action.payload;
314
+ })
295
315
  .addCase(queueSaveForm.rejected, (state) => {
296
316
  state.busy.saving = false;
297
317
  })
@@ -67,7 +67,7 @@ const <%= section.className %>FieldSet: FunctionComponent<FieldSetProps> = ({
67
67
  <p><%= value.constant %></p>
68
68
  <%_ } _%>
69
69
  <%_ } else { _%>
70
- <GoAFormItem label="<%= value.title || key %>" helpText="<%= value.description %>">
70
+ <GoAFormItem mb="m" label="<%= value.title || key %>" helpText="<%= value.description %>">
71
71
  <%_ switch(value.type) {
72
72
  case 'string': _%>
73
73
  <%_ if (value.enum) { _%>
@@ -129,7 +129,7 @@ const <%= section.className %>FieldSet: FunctionComponent<FieldSetProps> = ({
129
129
  disabled={isReadOnly || inReview}
130
130
  error={errors['<%= key %>']}
131
131
  placeholder="<%= value?.examples || []%>"
132
- onChange={(name, updated) => onChange({ ...value, [name]: updated })}
132
+ onChange={(name, updated) => onChange({ ...value, [name]: parseFloat(updated) })}
133
133
  value={`${value.<%= key %> || ''}`}
134
134
  name="<%= key %>"
135
135
  <%_ if (value?.maximum !== undefined) { _%>