Skip to content

Commit

Permalink
Do not submit id while updating modal
Browse files Browse the repository at this point in the history
- Also added more error catching and id validations
  • Loading branch information
BenjaVR committed Jan 8, 2019
1 parent 3520c37 commit e120b5b
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 19 deletions.
1 change: 0 additions & 1 deletion web/src/components/educations/EducationsFormModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,4 @@ class EducationFormModal extends React.Component<EducationFormModalProps, IEduca
}

const WrappedEducationFormModal = Form.create<IEducationFormModalProps>()(EducationFormModal);

export default WrappedEducationFormModal;
12 changes: 6 additions & 6 deletions web/src/components/educations/EducationsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ export default class EducationsPage extends React.Component<EducationsPageProps,
});
resolve();
})
.catch(() => {
.catch((error) => {
notification.error({
message: "Kon opleiding niet toevoegen",
});
reject();
reject(error);
});
});
}
Expand All @@ -133,11 +133,11 @@ export default class EducationsPage extends React.Component<EducationsPageProps,
});
resolve();
})
.catch(() => {
.catch((error) => {
notification.error({
message: "Kon opleiding niet bewerken",
});
reject();
reject(error);
});
});
}
Expand All @@ -151,11 +151,11 @@ export default class EducationsPage extends React.Component<EducationsPageProps,
});
resolve();
})
.catch(() => {
.catch((error) => {
notification.error({
message: `Kon opleiding "${education.name}" niet verwijderen, probeer later opnieuw`,
});
reject();
reject(error);
});
});
}
Expand Down
8 changes: 8 additions & 0 deletions web/src/components/layouts/AuthenticatedLayout.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
padding: 0 25px !important;
}

.titlColumn {
max-width: 50%;
}

.title {
overflow: hidden;
white-space: nowrap;
Expand Down Expand Up @@ -61,4 +65,8 @@

.avatar {
margin: 4px !important;

&:hover {
cursor: default; // Should be removed when using the avatar to go to profile settings or something like that.
}
}
2 changes: 1 addition & 1 deletion web/src/components/layouts/AuthenticatedLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class AuthenticatedLayout extends React.Component<IAuthenticatedLayoutProps, IAu
>
<Layout.Header className={styles.header}>
<Row type="flex" justify="space-between" align="middle">
<Col >
<Col className={styles.titlColumn}>
<h1 className={styles.title}>
{this.state.activeMenuItem.route.title}
</h1>
Expand Down
12 changes: 6 additions & 6 deletions web/src/components/schools/SchoolsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ export default class SchoolsPage extends React.Component<SchoolsPageProps, IScho
});
resolve();
})
.catch(() => {
.catch((error) => {
notification.error({
message: "Kon school niet toevoegen",
});
reject();
reject(error);
});
});
}
Expand All @@ -133,11 +133,11 @@ export default class SchoolsPage extends React.Component<SchoolsPageProps, IScho
});
resolve();
})
.catch(() => {
.catch((error) => {
notification.error({
message: "Kon school niet bewerken",
});
reject();
reject(error);
});
});
}
Expand All @@ -151,11 +151,11 @@ export default class SchoolsPage extends React.Component<SchoolsPageProps, IScho
});
resolve();
})
.catch(() => {
.catch((error) => {
notification.error({
message: `Kon school "${school.name}" niet verwijderen, probeer later opnieuw`,
});
reject();
reject(error);
});
});
}
Expand Down
1 change: 0 additions & 1 deletion web/src/models/Education.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ import { IFirebaseModel } from "../services/FirestoreServiceBase";

export interface IEducation extends IFirebaseModel {
name: string;
enabled: boolean;
}
30 changes: 26 additions & 4 deletions web/src/services/FirestoreServiceBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export abstract class FirestoreServiceBase<T extends IFirebaseModel> {

public add(obj: T): Promise<T> {
return new Promise<T>((resolve, reject): void => {
if (obj.id !== undefined) {
reject("Cannot add a object which already has an id!");
}

const now = Firebase.firestore.Timestamp.now();
obj.createdTimestamp = now;
obj.updatedTimestamp = now;
Expand All @@ -36,7 +40,10 @@ export abstract class FirestoreServiceBase<T extends IFirebaseModel> {
.then((doc) => {
resolve(this.mapDocToObject(doc));
})
.catch(reject);
.catch((error) => {
catchErrorDev(error);
reject(error);
});
});
}

Expand All @@ -46,11 +53,16 @@ export abstract class FirestoreServiceBase<T extends IFirebaseModel> {
reject("Id is undefined");
}

const id = obj.id;
delete obj.id;
obj.updatedTimestamp = Firebase.firestore.Timestamp.now();

this.collectionRef.doc(obj.id).update(obj)
this.collectionRef.doc(id).update(obj)
.then(() => resolve())
.catch(reject);
.catch((error) => {
catchErrorDev(error);
reject(error);
});
});
}

Expand All @@ -62,7 +74,10 @@ export abstract class FirestoreServiceBase<T extends IFirebaseModel> {

this.collectionRef.doc(obj.id).delete()
.then(resolve)
.catch(reject);
.catch((error) => {
catchErrorDev(error);
reject(error);
});
});
}

Expand All @@ -78,3 +93,10 @@ export abstract class FirestoreServiceBase<T extends IFirebaseModel> {
return obj as T;
}
}

function catchErrorDev(error: any): void {
if (process.env.NODE_ENV === "development") {
// tslint:disable-next-line:no-console
console.log(error);
}
}

0 comments on commit e120b5b

Please sign in to comment.