Skip to content

Commit 3198215

Browse files
author
Kevin Borrill
committed
Merged in feature/GFW-1050-add-teams-to-area (pull request #135)
Normal: Feature/GFW-1050 add teams to area (Medium) Approved-by: Owen Evans Approved-by: Uchenna Okafor
2 parents 0c3458d + bc60f96 commit 3198215

File tree

15 files changed

+383
-37
lines changed

15 files changed

+383
-37
lines changed

src/components/modals/FormModal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface IInputBase<T> {
1212
formatErrors?: (error: any) => any; // ToDo
1313
registerProps: {
1414
name: FieldPath<T>;
15-
options: RegisterOptions<T, FieldPath<T>>;
15+
options?: RegisterOptions<T, FieldPath<T>>;
1616
};
1717
}
1818

src/configureYup.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ setLocale({
44
// use constant translation keys for messages without values
55
mixed: {
66
default: values => ({ key: "errors.mixed.default", values }),
7-
notType: values => ({ key: "errors.mixed.notType", values })
7+
notType: values => ({ key: "errors.mixed.notType", values }),
8+
required: () => ({ key: "errors.mixed.required" })
89
},
910
// use functions to generate an error object that includes the value from the schema
1011
number: {
@@ -14,5 +15,8 @@ setLocale({
1415
string: {
1516
min: ({ min }) => ({ key: "errors.string.min", values: { min } }),
1617
email: () => ({ key: "errors.string.email" })
18+
},
19+
array: {
20+
min: ({ min }) => ({ key: "errors.array.min", values: { min } })
1721
}
1822
});

src/index.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
/* Utilities */
9797
@import "./styles/utilities/u-display";
9898
@import "./styles/utilities/u-width";
99+
@import "./styles/utilities/u-height";
99100
@import "./styles/utilities/u-font";
100101
@import "./styles/utilities/u-spacings";
101102
@import "./styles/utilities/u-position";

src/locales/en.json

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,20 @@
136136
"areas.details.templates.remove.body": "Unassign template from this area",
137137
"areas.details.templates.remove.success": "Successfully unassigned",
138138
"areas.details.templates.remove.error": "Failed to unassign, try again later",
139-
"areas.details.table.header.name": "Name",
140-
"areas.details.table.header.openAssignments": "Open Assignments",
139+
"areas.details.templatesTable.header.name": "Name",
140+
"areas.details.templatesTable.header.openAssignments": "Open Assignments",
141+
"areas.details.teams": "Teams attached to this area ({num})",
142+
"areas.details.teams.add.title": "Add Team",
143+
"areas.details.teams.add.select": "Select the teams you want to assign to this area.",
144+
"areas.details.teams.add.selectPlaceholder": "Select a team",
145+
"areas.details.teams.add.success": "Successfully added",
146+
"areas.details.teams.add.error": "Failed to add, try again later",
147+
"areas.details.teams.remove.title": "Unassign team",
148+
"areas.details.teams.remove.body": "Unassign team from this area",
149+
"areas.details.teams.remove.success": "Successfully unassigned",
150+
"areas.details.teams.remove.error": "Failed to unassign, try again later",
151+
"areas.details.teamsTable.header.name": "Name",
152+
"areas.details.teamsTable.header.reports": "Reports",
141153
"templates.name": "templates",
142154
"templates.title": "Your Templates",
143155
"templates.subtitle": "Your templates",
@@ -340,9 +352,11 @@
340352
"components.map.edit": "Edit",
341353
"components.map.delete": "Delete",
342354
"errors.mixed.default": "Incorrect value",
355+
"errors.mixed.required": "This field is required",
343356
"errors.mixed.notType": "Incorrect format, enter a {type}",
344357
"errors.string.email": "Must be a valid email",
345358
"errors.string.min": "Field must be at least {min} characters long",
359+
"errors.array.min": "At least {min, plural, one {# item is} other {# items are}} required",
346360
"errors.number.min": "This should be at least {min}",
347361
"errors.number.max": "This should be less than {max}",
348362
"errors.team.detail": "Could not find Team"

src/modules/areas.js renamed to src/modules/areas.ts

Lines changed: 65 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,61 @@
1+
// @ts-ignore - no types available
12
import normalize from "json-api-normalizer";
23
import { saveGeostore } from "./geostores";
34
import { toastr } from "react-redux-toastr";
45
import omit from "lodash/omit";
56
import { areaService } from "services/area";
67
import { utilsService } from "services/utils";
8+
import { AppDispatch, RootState } from "store";
9+
import { TGetTeamResponse } from "services/teams";
710

811
// Actions
912
const SET_AREA = "areas/SET_AREA";
1013
const SET_AREAS = "areas/SET_AREAS";
14+
const SET_AREA_TEAMS = "areas/SET_AREA_TEAMS";
1115
const SET_COUNTRIES = "areas/SET_COUNTRIES";
1216
const SET_LOADING_AREAS = "areas/SET_LOADING_AREAS";
1317
const SET_SAVING_AREA = "areas/SET_SAVING_AREA";
1418
const SET_EDITING_AREA = "areas/SET_EDITING_AREA";
1519
const SET_AREA_DELETED = "areas/SET_AREA_DELETED";
1620

21+
export type TAreasState = {
22+
ids: string[];
23+
data: any;
24+
countries: any[];
25+
areaTeams: TGetTeamResponse[];
26+
loading: boolean;
27+
saving: boolean;
28+
editing: boolean;
29+
error: boolean;
30+
};
31+
32+
export type TReducerActions =
33+
| { type: typeof SET_AREA; payload: any }
34+
| { type: typeof SET_AREAS; payload: any }
35+
| { type: typeof SET_AREA_TEAMS; payload: { areaTeams: TAreasState["areaTeams"] } }
36+
| { type: typeof SET_COUNTRIES; payload: any }
37+
| { type: typeof SET_LOADING_AREAS; payload: any }
38+
| { type: typeof SET_SAVING_AREA; payload: any }
39+
| { type: typeof SET_EDITING_AREA; payload: any }
40+
| { type: typeof SET_AREA_DELETED; payload: any };
41+
1742
// Reducer
18-
const initialState = {
43+
const initialState: TAreasState = {
1944
ids: [],
2045
data: {},
2146
countries: [],
47+
areaTeams: [],
2248
loading: true,
2349
saving: false,
2450
editing: false,
2551
error: false
2652
};
2753

28-
export default function reducer(state = initialState, action) {
54+
export default function reducer(state = initialState, action: TReducerActions): TAreasState {
2955
switch (action.type) {
3056
case SET_AREA: {
3157
const area = action.payload.area;
58+
//@ts-ignore - TODO: Figure out typescript error
3259
if (state.ids.indexOf(...Object.keys(area)) > -1) {
3360
return {
3461
...state,
@@ -47,6 +74,9 @@ export default function reducer(state = initialState, action) {
4774
if (areas) return Object.assign({}, state, { ids: Object.keys(areas), data: areas });
4875
return state;
4976
}
77+
case SET_AREA_TEAMS: {
78+
return Object.assign({}, state, { areaTeams: action.payload });
79+
}
5080
case SET_AREA_DELETED: {
5181
const areaId = action.payload;
5282
const ids = state.ids.filter(id => id !== areaId);
@@ -67,8 +97,8 @@ export default function reducer(state = initialState, action) {
6797
}
6898

6999
// Action Creators
70-
export function getArea(id) {
71-
return (dispatch, state) => {
100+
export function getArea(id: string) {
101+
return (dispatch: AppDispatch, state: () => RootState) => {
72102
dispatch({
73103
type: SET_LOADING_AREAS,
74104
payload: true
@@ -100,8 +130,8 @@ export function getArea(id) {
100130
};
101131
}
102132

103-
export function deleteArea(areaId) {
104-
return (dispatch, state) => {
133+
export function deleteArea(areaId: string) {
134+
return (dispatch: AppDispatch, state: () => RootState) => {
105135
areaService.token = state().user.token;
106136
areaService
107137
.deleteArea(areaId)
@@ -118,7 +148,7 @@ export function deleteArea(areaId) {
118148
}
119149

120150
export function getAreas() {
121-
return (dispatch, state) => {
151+
return (dispatch: AppDispatch, state: () => RootState) => {
122152
dispatch({
123153
type: SET_LOADING_AREAS,
124154
payload: true
@@ -148,8 +178,25 @@ export function getAreas() {
148178
};
149179
}
150180

181+
export function getAreaTeams(areaId: string) {
182+
return (dispatch: AppDispatch, state: () => RootState) => {
183+
return areaService
184+
.getAreaTeams(areaId)
185+
.then(data => {
186+
dispatch({
187+
type: SET_AREA_TEAMS,
188+
payload: data
189+
});
190+
return data;
191+
})
192+
.catch(error => {
193+
toastr.error("Unable to load area teams", error);
194+
});
195+
};
196+
}
197+
151198
export function getCountries() {
152-
return (dispatch, state) => {
199+
return (dispatch: AppDispatch) => {
153200
return utilsService
154201
.getCountries()
155202
.then(data => {
@@ -165,8 +212,8 @@ export function getCountries() {
165212
}
166213

167214
// POST name, geostore ID
168-
export function saveArea(area, node, method) {
169-
return async (dispatch, state) => {
215+
export function saveArea(area: any, node: HTMLElement, method: string) {
216+
return async (dispatch: AppDispatch, state: () => RootState) => {
170217
dispatch({
171218
type: SET_SAVING_AREA,
172219
payload: {
@@ -204,35 +251,35 @@ export function saveArea(area, node, method) {
204251
}
205252

206253
// async save geostore then area
207-
export function saveAreaWithGeostore(area, node, method) {
208-
return async (dispatch, state) => {
254+
export function saveAreaWithGeostore(area: any, node: HTMLElement, method: string) {
255+
return async (dispatch: AppDispatch) => {
209256
const geostore = await dispatch(saveGeostore(area.geojson));
210257
const geostoreId = Object.keys(geostore)[0];
211258
const areaWithGeostore = { ...area, geostore: geostoreId };
212259
await dispatch(saveArea(areaWithGeostore, node, method));
213260
};
214261
}
215262

216-
export function setEditing(bool) {
217-
return async dispatch => {
263+
export function setEditing(bool: boolean) {
264+
return async (dispatch: AppDispatch) => {
218265
await dispatch({
219266
type: SET_EDITING_AREA,
220267
payload: bool
221268
});
222269
};
223270
}
224271

225-
export function setSaving(payload) {
226-
return dispatch => {
272+
export function setSaving(payload: boolean) {
273+
return (dispatch: AppDispatch) => {
227274
dispatch({
228275
type: SET_SAVING_AREA,
229276
payload: payload
230277
});
231278
};
232279
}
233280

234-
export function setLoading(bool) {
235-
return dispatch => {
281+
export function setLoading(bool: boolean) {
282+
return (dispatch: AppDispatch) => {
236283
dispatch({
237284
type: SET_LOADING_AREAS,
238285
payload: bool

src/modules/templates.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const initialState: TTemplatesState = {
4343
error: false
4444
};
4545

46-
export default function reducer(state = initialState, action: TReducerActions) {
46+
export default function reducer(state = initialState, action: TReducerActions): TTemplatesState {
4747
switch (action.type) {
4848
case SET_TEMPLATE: {
4949
const template = action.payload.reports;

0 commit comments

Comments
 (0)