@@ -15,6 +15,7 @@ import {selectTaskUpsert} from "../../redux/modals/modals.selectors";
|
|||||||
import {selectBodyshop, selectCurrentUser} from "../../redux/user/user.selectors";
|
import {selectBodyshop, selectCurrentUser} from "../../redux/user/user.selectors";
|
||||||
import TaskUpsertModalComponent from "./task-upsert-modal.component";
|
import TaskUpsertModalComponent from "./task-upsert-modal.component";
|
||||||
import {replaceUndefinedWithNull} from "../../utils/undefinedtonull.js";
|
import {replaceUndefinedWithNull} from "../../utils/undefinedtonull.js";
|
||||||
|
import {useNavigate} from "react-router-dom";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
currentUser: selectCurrentUser,
|
currentUser: selectCurrentUser,
|
||||||
@@ -32,6 +33,7 @@ export function TaskUpsertModalContainer({
|
|||||||
toggleModalVisible,
|
toggleModalVisible,
|
||||||
}) {
|
}) {
|
||||||
const {t} = useTranslation();
|
const {t} = useTranslation();
|
||||||
|
const history = useNavigate();
|
||||||
const [insertTask] = useMutation(MUTATION_INSERT_NEW_TASK);
|
const [insertTask] = useMutation(MUTATION_INSERT_NEW_TASK);
|
||||||
const [updateTask] = useMutation(MUTATION_UPDATE_TASK);
|
const [updateTask] = useMutation(MUTATION_UPDATE_TASK);
|
||||||
const {open, context, actions} = taskUpsert;
|
const {open, context, actions} = taskUpsert;
|
||||||
@@ -51,7 +53,11 @@ export function TaskUpsertModalContainer({
|
|||||||
skip: !jobIdState,
|
skip: !jobIdState,
|
||||||
});
|
});
|
||||||
|
|
||||||
const {loading: taskLoading, error: taskError, data: taskData} = useQuery(QUERY_GET_TASK_BY_ID, {
|
const {
|
||||||
|
loading: taskLoading,
|
||||||
|
error: taskError,
|
||||||
|
data: taskData
|
||||||
|
} = useQuery(QUERY_GET_TASK_BY_ID, {
|
||||||
variables: {id: taskId},
|
variables: {id: taskId},
|
||||||
skip: !taskId,
|
skip: !taskId,
|
||||||
});
|
});
|
||||||
@@ -110,6 +116,12 @@ export function TaskUpsertModalContainer({
|
|||||||
}, [loading, error, data]);
|
}, [loading, error, data]);
|
||||||
|
|
||||||
|
|
||||||
|
const removeTaskIdFromUrl = () => {
|
||||||
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
|
urlParams.delete('taskid');
|
||||||
|
history(`${window.location.pathname}?${urlParams}`);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle the form submit
|
* Handle the form submit
|
||||||
* @param formValues
|
* @param formValues
|
||||||
@@ -124,8 +136,8 @@ export function TaskUpsertModalContainer({
|
|||||||
task: replaceUndefinedWithNull(values)
|
task: replaceUndefinedWithNull(values)
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
window.dispatchEvent( new CustomEvent('taskUpdated', {
|
window.dispatchEvent(new CustomEvent('taskUpdated', {
|
||||||
detail: { message: 'A task has been created or edited.' },
|
detail: {message: 'A task has been created or edited.'},
|
||||||
}));
|
}));
|
||||||
notification["success"]({
|
notification["success"]({
|
||||||
message: t("tasks.successes.updated"),
|
message: t("tasks.successes.updated"),
|
||||||
@@ -164,8 +176,8 @@ export function TaskUpsertModalContainer({
|
|||||||
if (refetch) await refetch();
|
if (refetch) await refetch();
|
||||||
form.resetFields();
|
form.resetFields();
|
||||||
toggleModalVisible();
|
toggleModalVisible();
|
||||||
window.dispatchEvent( new CustomEvent('taskUpdated', {
|
window.dispatchEvent(new CustomEvent('taskUpdated', {
|
||||||
detail: { message: 'A task has been created or edited.' },
|
detail: {message: 'A task has been created or edited.'},
|
||||||
}));
|
}));
|
||||||
notification["success"]({
|
notification["success"]({
|
||||||
message: t("tasks.successes.created"),
|
message: t("tasks.successes.created"),
|
||||||
@@ -180,16 +192,18 @@ export function TaskUpsertModalContainer({
|
|||||||
okText={t("general.actions.save")}
|
okText={t("general.actions.save")}
|
||||||
width="50%"
|
width="50%"
|
||||||
onOk={() => {
|
onOk={() => {
|
||||||
|
removeTaskIdFromUrl();
|
||||||
form.submit();
|
form.submit();
|
||||||
}}
|
}}
|
||||||
onCancel={() => {
|
onCancel={() => {
|
||||||
|
removeTaskIdFromUrl();
|
||||||
toggleModalVisible();
|
toggleModalVisible();
|
||||||
}}
|
}}
|
||||||
|
|
||||||
destroyOnClose
|
destroyOnClose
|
||||||
>
|
>
|
||||||
<Form form={form} onFinish={handleFinish} layout="vertical">
|
<Form form={form} onFinish={handleFinish} layout="vertical">
|
||||||
<TaskUpsertModalComponent form={form} loading={loading} error={error} data={data}
|
<TaskUpsertModalComponent form={form} loading={loading || (taskId && taskLoading)} error={error} data={data}
|
||||||
selectedJobId={selectedJobId}
|
selectedJobId={selectedJobId}
|
||||||
setSelectedJobId={setSelectedJobId}
|
setSelectedJobId={setSelectedJobId}
|
||||||
selectedJobDetails={selectedJobDetails}/>
|
selectedJobDetails={selectedJobDetails}/>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import React, {useEffect} from "react";
|
import React, {useEffect} from "react";
|
||||||
import {useTranslation} from "react-i18next";
|
import {useTranslation} from "react-i18next";
|
||||||
import TasksPageComponent from "./tasks.page.component";
|
import TasksPageComponent from "./tasks.page.component";
|
||||||
|
import queryString from "query-string";
|
||||||
|
|
||||||
import {connect} from "react-redux";
|
import {connect} from "react-redux";
|
||||||
import {createStructuredSelector} from "reselect";
|
import {createStructuredSelector} from "reselect";
|
||||||
@@ -9,6 +10,7 @@ import InstanceRenderManager from "../../utils/instanceRenderMgr.js";
|
|||||||
import {selectBodyshop, selectCurrentUser} from "../../redux/user/user.selectors.js";
|
import {selectBodyshop, selectCurrentUser} from "../../redux/user/user.selectors.js";
|
||||||
import TaskPageTypes from "./taskPageTypes.jsx";
|
import TaskPageTypes from "./taskPageTypes.jsx";
|
||||||
import {setModalContext} from "../../redux/modals/modals.actions.js";
|
import {setModalContext} from "../../redux/modals/modals.actions.js";
|
||||||
|
import {useLocation} from "react-router-dom";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
bodyshop: selectBodyshop,
|
bodyshop: selectBodyshop,
|
||||||
@@ -29,6 +31,7 @@ export function MyTasksPageContainer({
|
|||||||
setTaskUpsertContext
|
setTaskUpsertContext
|
||||||
}) {
|
}) {
|
||||||
const {t} = useTranslation();
|
const {t} = useTranslation();
|
||||||
|
const searchParams = queryString.parse((useLocation().search));
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
document.title = t("titles.all_tasks", {
|
document.title = t("titles.all_tasks", {
|
||||||
app: InstanceRenderManager({
|
app: InstanceRenderManager({
|
||||||
@@ -48,8 +51,7 @@ export function MyTasksPageContainer({
|
|||||||
// This takes care of the ability to deep link a task from the URL (Dispatches the modal)
|
// This takes care of the ability to deep link a task from the URL (Dispatches the modal)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Check for a query string in the URL
|
// Check for a query string in the URL
|
||||||
const queryString = window.location.search;
|
const urlParams = new URLSearchParams(searchParams);
|
||||||
const urlParams = new URLSearchParams(queryString);
|
|
||||||
const taskId = urlParams.get('taskid');
|
const taskId = urlParams.get('taskid');
|
||||||
if (taskId) {
|
if (taskId) {
|
||||||
setTaskUpsertContext({
|
setTaskUpsertContext({
|
||||||
@@ -57,6 +59,7 @@ export function MyTasksPageContainer({
|
|||||||
taskId,
|
taskId,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
urlParams.delete('taskid');
|
||||||
}
|
}
|
||||||
}, [setTaskUpsertContext]);
|
}, [setTaskUpsertContext]);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user