diff --git a/package-lock.json b/package-lock.json index 9cc68df7..84a1acdc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3631,6 +3631,11 @@ "resolved": "https://registry.npmjs.org/@types/trusted-types/-/trusted-types-2.0.2.tgz", "integrity": "sha512-F5DIZ36YVLE+PN+Zwws4kJogq47hNgX3Nx6WyDJ3kcplxyke3XIzB8uK5n/Lpm1HBsbGzd6nmGehL8cPekP+Tg==" }, + "@types/uuid": { + "version": "8.3.4", + "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-8.3.4.tgz", + "integrity": "sha512-c/I8ZRb51j+pYGAu5CrFMRxqZ2ke4y2grEBO5AUjgSkSk+qT2Ea+OdWElz/OiMf5MNpn2b17kuVBwZLQJXzihw==" + }, "@types/ws": { "version": "8.5.3", "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.3.tgz", diff --git a/package.json b/package.json index a1f46553..8609dc98 100644 --- a/package.json +++ b/package.json @@ -17,13 +17,15 @@ "@types/react": "^16.14.24", "@types/react-dom": "^16.9.14", "@types/react-redux": "^7.1.23", + "@types/uuid": "^8.3.4", "date-fns": "^2.28.0", "react": "^17.0.2", "react-dom": "^17.0.2", "react-redux": "^7.2.6", "react-router-dom": "^6.2.2", "react-scripts": "5.0.0", - "typescript": "~4.1.5" + "typescript": "~4.1.5", + "uuid": "^8.3.2" }, "scripts": { "start": "react-scripts start", diff --git a/src/components/TrackerCard/TrackerCard.spec.tsx b/src/components/TrackerCard/TrackerCard.spec.tsx index 7c33d547..19124816 100644 --- a/src/components/TrackerCard/TrackerCard.spec.tsx +++ b/src/components/TrackerCard/TrackerCard.spec.tsx @@ -3,8 +3,10 @@ import { subDays } from 'date-fns'; import TrackerStatus from '../../models/TrackerStatus'; import formatDate from '../../utils/formatDate'; import TrackerCard from './TrackerCard'; +import { v4 } from 'uuid'; const tracker1 = { + id: v4(), beginDate: subDays(new Date(), 3).toString(), defaultQuantity: 15, duration: 13, diff --git a/src/models/Tracker.ts b/src/models/Tracker.ts index b34b166e..7ade29c0 100644 --- a/src/models/Tracker.ts +++ b/src/models/Tracker.ts @@ -1,6 +1,7 @@ import TrackerEntry from './TrackerEntry'; import TrackerStatus from './TrackerStatus'; export default interface Tracker { + id: string; // uuid v4 beginDate: string; dateHidden?: string; defaultQuantity?: number; diff --git a/src/models/TrackerEntry.ts b/src/models/TrackerEntry.ts index e82daf34..dc9a3718 100644 --- a/src/models/TrackerEntry.ts +++ b/src/models/TrackerEntry.ts @@ -1,4 +1,5 @@ export default interface TrackerEntry { + id: string; // uuid v4 date: string; quantity: number; } diff --git a/src/store/trackers/trackers.actions.ts b/src/store/trackers/trackers.actions.ts index cad44ed2..116c029c 100644 --- a/src/store/trackers/trackers.actions.ts +++ b/src/store/trackers/trackers.actions.ts @@ -1,6 +1,7 @@ import { subDays } from 'date-fns'; import Tracker from '../../models/Tracker'; import TrackerStatus from '../../models/TrackerStatus'; +import { v4 as uuidv4 } from 'uuid'; class TrackersActions { // A mock function to mimic making an async request for data @@ -11,6 +12,7 @@ class TrackersActions { resolve({ data: [ { + id: uuidv4(), beginDate: new Date().toString(), name: "Boire plus d'eau", defaultQuantity: 1, @@ -19,6 +21,7 @@ class TrackersActions { entries: [] }, { + id: uuidv4(), beginDate: new Date().toString(), defaultQuantity: 1, name: 'Faire du yoga', @@ -27,6 +30,7 @@ class TrackersActions { entries: [] }, { + id: uuidv4(), beginDate: subDays(new Date(), 7).toString(), defaultQuantity: 15, duration: 45, diff --git a/src/store/trackers/trackers.selectors.spec.ts b/src/store/trackers/trackers.selectors.spec.ts index b1ca632e..31f87ce9 100644 --- a/src/store/trackers/trackers.selectors.spec.ts +++ b/src/store/trackers/trackers.selectors.spec.ts @@ -1,3 +1,4 @@ +import { v4 } from 'uuid'; import SliceStatus from '../../models/SliceStatus'; import Tracker from '../../models/Tracker'; import TrackerStatus from '../../models/TrackerStatus'; @@ -18,6 +19,7 @@ describe('trackers selector', () => { ...state.trackers, trackers: [ { + id: v4(), beginDate: new Date().toString(), entries: [], name: 'Do', @@ -26,6 +28,7 @@ describe('trackers selector', () => { unit: 'push-ups' }, { + id: v4(), beginDate: new Date().toString(), duration: 10, entries: [],