Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auto reload the content when we submit a service or confirm a service #327

Merged
merged 3 commits into from
Jan 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions frontend/src/views/users/service_modal/ServiceModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface ServiceModalProps<T> {
user: User;
service?: Service;
onClose: (e?: React.MouseEvent<HTMLButtonElement>) => void;
onServiceConfirmed: (service: Service) => Promise<void>;
isOpen: boolean;
serviceStore?: ServiceStore;
mainStore?: MainStore;
Expand Down Expand Up @@ -128,17 +129,16 @@ export class ServiceModal extends React.Component<ServiceModalProps<Service>, {
);
}

handleInformationChecked = () => {
this.setState({ informationChecked: !this.state.informationChecked });
}

onConfirmationPut = () => {
this.props.serviceStore!.doConfirmPut(this.props.service!.id!).then(() => {
this.props.mainStore!.displaySuccess('Speichern erfolgreich');
if (this.props.onServiceConfirmed != null) {
this.props.onServiceConfirmed(this.props.service!).then(() => {
this.props.mainStore!.displaySuccess('Speichern erfolgreich');
});
}
}

// TODO: remove reload (layzness)
setTimeout(() => window.location.reload(), 2000);
});
handleInformationChecked = () => {
this.setState({ informationChecked: !this.state.informationChecked });
}

private updateEndingOrServiceDays = async (current: any, next: any, formik: any) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ function onServiceTableSubmit(serviceStore?: ServiceStore, userStore?: UserStore
};
}

function confirmService(serviceStore?: ServiceStore, userStore?: UserStore) {
return (service: Service) => {
return serviceStore!.doConfirmPut(service.id!).then(() => {
userStore!.fetchOne(service.user_id);
});
};
}

function onServiceAddExpenseSheet(service: Service, expenseSheetStore: ExpenseSheetStore, userStore: UserStore) {
expenseSheetStore.createAdditional(service.id!).then(value => {
userStore.fetchOne(service.user_id);
Expand Down Expand Up @@ -172,6 +180,7 @@ export default (params: OverviewTableParams) => {
{getOverviewButtons(service)}
<ServiceModal
onSubmit={onServiceTableSubmit(serviceStore, userStore)}
onServiceConfirmed={confirmService(serviceStore, userStore)}
user={user}
service={service}
onClose={onModalClose}
Expand Down
17 changes: 16 additions & 1 deletion frontend/src/views/users/service_subform/ServiceSubform.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,22 @@ class ServiceSubformInner extends React.Component<Props, ServiceSubformState> {
this.state = { service_id: undefined, new_service: false };
}

submitService = (service: Service) => {
return this.props.serviceStore!.post(serviceSchema.cast(service)).then(() => {
this.props.userStore!.fetchOne(this.props.user.id);
});
}

confirmService = (service: Service) => {
return this.props.serviceStore!.doConfirmPut(service.id!).then(() => {
this.props.userStore!.fetchOne(service.user_id);
});
}

render() {
const { user, serviceStore, mainStore, userStore, serviceSpecificationStore, expenseSheetStore, classes, theme } = this.props;
const submitService = this.submitService;
const confirmService = this.confirmService;

return (
<>
Expand Down Expand Up @@ -83,7 +97,8 @@ class ServiceSubformInner extends React.Component<Props, ServiceSubformState> {
Neue Einsatzplanung hinzufügen
</Button>
<ServiceModal
onSubmit={(service: Service) => serviceStore!.post(serviceSchema.cast(service))}
onSubmit={submitService}
onServiceConfirmed={confirmService}
user={user}
onClose={() => {
this.setState({ new_service: false });
Expand Down