From 1b57ede13949aa296d8372d119cb86d90a0010fe Mon Sep 17 00:00:00 2001 From: Thai Date: Sun, 13 Sep 2020 13:50:13 -0700 Subject: [PATCH 1/5] Tsconfig changes again : ( --- package-lock.json | 18 ++++++++-------- tsconfig.json | 54 +++++++++++++++++++++++------------------------ 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/package-lock.json b/package-lock.json index 411f45c1..274825bb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12716,7 +12716,7 @@ }, "chownr": { "version": "1.1.2", - "resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.2.tgz", + "resolved": false, "integrity": "sha512-GkfeAQh+QNy3wquu9oIZr6SS5x7wGdSgNQvD10X3r+AZr1Oys22HW8kAmDMvNg2+Dm0TeGaEuO8gFwdBXxwO8A==" }, "code-point-at": { @@ -12764,7 +12764,7 @@ }, "fs-minipass": { "version": "1.2.6", - "resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-1.2.6.tgz", + "resolved": false, "integrity": "sha512-crhvyXcMejjv3Z5d2Fa9sf5xLYVCF5O1c71QxbVnbLsmYMBEvDAftewesN/HhY03YRoA7zOMxjNGrF5svGaaeQ==", "requires": { "minipass": "^2.2.1" @@ -12866,12 +12866,12 @@ }, "minimist": { "version": "1.2.0", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", + "resolved": false, "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=" }, "minipass": { "version": "2.3.5", - "resolved": "https://registry.npmjs.org/minipass/-/minipass-2.3.5.tgz", + "resolved": false, "integrity": "sha512-Gi1W4k059gyRbyVUZQ4mEqLm0YIUiGYfvxhF6SIlk3ui1WVxMTGfGdQ2SInh3PDrRTVvPKgULkpJtT4RH10+VA==", "requires": { "safe-buffer": "^5.1.2", @@ -12880,7 +12880,7 @@ }, "minizlib": { "version": "1.2.1", - "resolved": "https://registry.npmjs.org/minizlib/-/minizlib-1.2.1.tgz", + "resolved": false, "integrity": "sha512-7+4oTUOWKg7AuL3vloEWekXY2/D20cevzsrNT2kGWm+39J9hGTCBv8VI5Pm5lXZ/o3/mdR4f8rflAPhnQb8mPA==", "requires": { "minipass": "^2.2.1" @@ -12888,7 +12888,7 @@ }, "mkdirp": { "version": "0.5.1", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", + "resolved": false, "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", "requires": { "minimist": "0.0.8" @@ -12896,7 +12896,7 @@ "dependencies": { "minimist": { "version": "0.0.8", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", + "resolved": false, "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=" } } @@ -13121,7 +13121,7 @@ }, "tar": { "version": "4.4.10", - "resolved": "https://registry.npmjs.org/tar/-/tar-4.4.10.tgz", + "resolved": false, "integrity": "sha512-g2SVs5QIxvo6OLp0GudTqEf05maawKUxXru104iaayWA09551tFCTI8f1Asb4lPfkBr91k07iL4c11XO3/b0tA==", "requires": { "chownr": "^1.1.1", @@ -13153,7 +13153,7 @@ }, "yallist": { "version": "3.0.3", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.0.3.tgz", + "resolved": false, "integrity": "sha512-S+Zk8DEWE6oKpV+vI3qWkaK+jSbIK86pCwe2IF/xwIpQ8jEuxpw9NyaGjmp9+BoJv5FV2piqCDcoCtStppiq2A==" } } diff --git a/tsconfig.json b/tsconfig.json index d4fca364..75325e2f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,27 +1,27 @@ -{ - "compilerOptions": { - "target": "es5", - "lib": [ - "dom", - "dom.iterable", - "esnext" - ], - "allowJs": true, - "skipLibCheck": true, - "esModuleInterop": true, - "allowSyntheticDefaultImports": true, - "strict": true, - "forceConsistentCasingInFileNames": true, - "module": "esnext", - "moduleResolution": "node", - "resolveJsonModule": true, - "isolatedModules": true, - "noEmit": true, - "jsx": "react", - "baseUrl": "." - }, - "include": [ - "src" - ], - "extends": "./tsconfig.paths.json" -} +{ + "compilerOptions": { + "target": "es5", + "lib": [ + "dom", + "dom.iterable", + "esnext" + ], + "allowJs": true, + "skipLibCheck": true, + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "strict": true, + "forceConsistentCasingInFileNames": true, + "module": "esnext", + "moduleResolution": "node", + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react", + "baseUrl": "." + }, + "include": [ + "src" + ], + "extends": "./tsconfig.paths.json" +} From d22c13d39e64e9dbb0282504f85565abb95ef438 Mon Sep 17 00:00:00 2001 From: Thai Date: Tue, 15 Sep 2020 23:45:00 -0700 Subject: [PATCH 2/5] Fixed merge issue --- src/pages/App/index.tsx | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/src/pages/App/index.tsx b/src/pages/App/index.tsx index dfcfaef7..45bc02e6 100644 --- a/src/pages/App/index.tsx +++ b/src/pages/App/index.tsx @@ -16,18 +16,16 @@ import { EventDetailsPage, EventSignInPage, EventRsvpPage, - QueriedEventPage, } from '@Pages'; import { Loading } from '@SharedComponents'; import { UserContext, UserContextValues } from '@Contexts'; import * as ROUTES from '@Constants/routes'; -import { getRolesFromClaims } from '@Services/claims'; +import { getUserRole } from '@Services/UserService'; import { InducteeRoutingPermission, OfficerRoutingPermission, } from '@HOCs/RoutingPermissions'; import ApiConfigStore from '@Services/ApiConfigStore'; -import { config } from '@Config'; function App(): JSX.Element { const [userClaims, setUserClaims] = useState(null); @@ -40,9 +38,14 @@ function App(): JSX.Element { const tokenResult = await user.getIdTokenResult(); const { claims, token } = tokenResult; + // TODO: Add ApiConfigStore.setToken(token || '') here so getUserRole() works + + const id = parseInt(claims.user_id, 10); + const userRole = await getUserRole(id); + setUserClaims({ userId: claims.user_id, - userRoles: getRolesFromClaims(claims), + userRoles: [userRole.role], }); setUserToken(token); setIsLoading(false); @@ -55,12 +58,24 @@ function App(): JSX.Element { }, []); // eslint-disable-next-line camelcase - const setClaims = (claims: { user_id: string }) => { + const setClaims = async (claims: { user_id: string }): Promise => { + /* TODO: Remove the line below bc userToken might not be set by the time setClaims + * is run. Given that setClaims() is run after onAuthStateChanged(), this setToken() + * call is going to override whatever was the token with empty string if userToken + * is not set by the time this function is called (which happened to me). + * + * So it's best to remove this line. + * + * - Thai + */ ApiConfigStore.setToken(userToken || ''); + const id = parseInt(claims.user_id, 10); + const userRole = await getUserRole(id); + setUserClaims({ userId: claims.user_id, - userRoles: getRolesFromClaims(claims), + userRoles: [userRole.role], }); }; @@ -115,11 +130,6 @@ function App(): JSX.Element { path={ROUTES.CALENDAR} render={props => InducteeRoutingPermission(CalendarPage)(props)} /> - } - /> Date: Wed, 16 Sep 2020 01:57:57 -0700 Subject: [PATCH 3/5] Create Event now works properly and as intended. After creating an event, the browser redirects to the newly created event's EventDetails page. Note that fbURL and canvaURL both have to either be empty or filled out with a proper URL string, otherwise a status code 400 will be sent from the backend server. --- src/pages/App/index.tsx | 6 +++ src/pages/EventCreationPage/index.tsx | 11 ++++- src/services/api/.openapi-generator/FILES | 52 ++++++++++----------- src/services/api/.openapi-generator/VERSION | 2 +- 4 files changed, 43 insertions(+), 28 deletions(-) diff --git a/src/pages/App/index.tsx b/src/pages/App/index.tsx index 06ae775e..8b3863a0 100644 --- a/src/pages/App/index.tsx +++ b/src/pages/App/index.tsx @@ -16,6 +16,7 @@ import { EventDetailsPage, EventSignInPage, EventRsvpPage, + QueriedEventPage, } from '@Pages'; import { Loading } from '@SharedComponents'; import { UserContext, UserContextValues } from '@Contexts'; @@ -124,6 +125,11 @@ function App(): JSX.Element { path={ROUTES.CALENDAR} render={props => InducteeRoutingPermission(CalendarPage)(props)} /> + } + /> void ) => { - const createdEvent = await createEvent(values); + const submission = { + ...values, + hosts: values.hosts.map(host => { + return { id: host.id }; + }), + fbURL: values.fbURL === '' ? undefined : values.fbURL, + canvaURL: values.canvaURL === '' ? undefined : values.canvaURL, + }; + + const createdEvent = await createEvent(submission); const { id } = createdEvent; setSubmitting(false); diff --git a/src/services/api/.openapi-generator/FILES b/src/services/api/.openapi-generator/FILES index 426df699..dfb244f0 100644 --- a/src/services/api/.openapi-generator/FILES +++ b/src/services/api/.openapi-generator/FILES @@ -1,28 +1,28 @@ -apis/AuthApi.ts -apis/EventApi.ts -apis/UserApi.ts -apis/index.ts +apis\AuthApi.ts +apis\EventApi.ts +apis\UserApi.ts +apis\index.ts index.ts -models/AppUserEventRequest.ts -models/AppUserEventResponse.ts -models/AppUserInductionClass.ts -models/AppUserNameResponse.ts -models/AppUserPKPayload.ts -models/AppUserPostRequest.ts -models/AppUserProfileResponse.ts -models/AppUserResponse.ts -models/AppUserRolesResponse.ts -models/AppUserSignupRequest.ts -models/AttendanceResponse.ts -models/BaseEventPayload.ts -models/EventAttendanceResponse.ts -models/EventRSVPResponse.ts -models/EventRequest.ts -models/EventResponse.ts -models/MultipleAppUserResponse.ts -models/MultipleEventResponse.ts -models/MultipleUserNameResponse.ts -models/MultipleUserQuery.ts -models/RSVPResponse.ts -models/index.ts +models\AppUserEventRequest.ts +models\AppUserEventResponse.ts +models\AppUserInductionClass.ts +models\AppUserNameResponse.ts +models\AppUserPKPayload.ts +models\AppUserPostRequest.ts +models\AppUserProfileResponse.ts +models\AppUserResponse.ts +models\AppUserRolesResponse.ts +models\AppUserSignupRequest.ts +models\AttendanceResponse.ts +models\BaseEventPayload.ts +models\EventAttendanceResponse.ts +models\EventRSVPResponse.ts +models\EventRequest.ts +models\EventResponse.ts +models\MultipleAppUserResponse.ts +models\MultipleEventResponse.ts +models\MultipleUserNameResponse.ts +models\MultipleUserQuery.ts +models\RSVPResponse.ts +models\index.ts runtime.ts diff --git a/src/services/api/.openapi-generator/VERSION b/src/services/api/.openapi-generator/VERSION index 1a487e1a..8836c812 100644 --- a/src/services/api/.openapi-generator/VERSION +++ b/src/services/api/.openapi-generator/VERSION @@ -1 +1 @@ -5.0.0-beta2 \ No newline at end of file +5.0.0-beta \ No newline at end of file From 5d2e795977be24a1dd922de6c10708ef7f5db125 Mon Sep 17 00:00:00 2001 From: Thai Date: Wed, 16 Sep 2020 02:22:00 -0700 Subject: [PATCH 4/5] Added url validation to create event form's schema's fbURL + canvaURL. --- .../components/EventCreationForm/schema.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/pages/EventCreationPage/components/EventCreationForm/schema.ts b/src/pages/EventCreationPage/components/EventCreationForm/schema.ts index 899cc68b..1df403e4 100644 --- a/src/pages/EventCreationPage/components/EventCreationForm/schema.ts +++ b/src/pages/EventCreationPage/components/EventCreationForm/schema.ts @@ -8,8 +8,10 @@ const schema = Yup.object({ location: Yup.string().required('Required'), description: Yup.string().required('Required'), hosts: Yup.array().required('Required'), - fbURL: Yup.string(), - canvaURL: Yup.string(), + fbURL: Yup.string().url('Please either enter a valid URL or leave it blank'), + canvaURL: Yup.string().url( + 'Please either enter a valid URL or leave it blank' + ), }); export default schema; From d6d37f0b9e0a70c7478f561e362670c06544fd7e Mon Sep 17 00:00:00 2001 From: Thai Date: Wed, 16 Sep 2020 15:44:20 -0700 Subject: [PATCH 5/5] Changed process.env in src/index.js to using config. --- src/pages/App/index.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pages/App/index.tsx b/src/pages/App/index.tsx index 8b3863a0..4aa6ec73 100644 --- a/src/pages/App/index.tsx +++ b/src/pages/App/index.tsx @@ -27,6 +27,7 @@ import { OfficerRoutingPermission, } from '@HOCs/RoutingPermissions'; import ApiConfigStore from '@Services/ApiConfigStore'; +import { config } from '@Config'; function App(): JSX.Element { const [userClaims, setUserClaims] = useState(null); @@ -157,4 +158,4 @@ function App(): JSX.Element { ); } -export default process.env.NODE_ENV === 'development' ? hot(App) : App; +export default config.nodeEnv === 'development' ? hot(App) : App;