Fixed modal form

This commit is contained in:
Akmal Isomadinov 2024-07-26 15:57:28 +05:00
parent 6ce5cc24ca
commit fbbf03f366
5 changed files with 45 additions and 8 deletions

View File

@ -32,7 +32,7 @@ import FilesFilter from "@docspace/shared/api/files/filter";
import RoomsFilter from "@docspace/shared/api/rooms/filter"; import RoomsFilter from "@docspace/shared/api/rooms/filter";
import { getGroup } from "@docspace/shared/api/groups"; import { getGroup } from "@docspace/shared/api/groups";
import { getUserById } from "@docspace/shared/api/people"; import { getUserById } from "@docspace/shared/api/people";
import { MEDIA_VIEW_URL } from "@docspace/shared/constants"; import { CREATED_FORM_KEY, MEDIA_VIEW_URL } from "@docspace/shared/constants";
import { import {
Events, Events,
@ -78,6 +78,7 @@ const useFiles = ({
scrollToTop, scrollToTop,
selectedFolderStore, selectedFolderStore,
wsCreatedPDFForm,
}) => { }) => {
const navigate = useNavigate(); const navigate = useNavigate();
const { id } = useParams(); const { id } = useParams();
@ -292,7 +293,15 @@ const useFiles = ({
); );
} else { } else {
const folderId = filter.folder; const folderId = filter.folder;
return fetchFiles(folderId, filter); return fetchFiles(folderId, filter)?.finally(() => {
const data = sessionStorage.getItem(CREATED_FORM_KEY);
if (data) {
wsCreatedPDFForm({
data,
});
sessionStorage.removeItem(CREATED_FORM_KEY);
}
});
} }
} }

View File

@ -160,6 +160,7 @@ const PureHome = (props) => {
getFolderModel, getFolderModel,
scrollToTop, scrollToTop,
isEmptyGroups, isEmptyGroups,
wsCreatedPDFForm,
} = props; } = props;
//console.log(t("ComingSoon")) //console.log(t("ComingSoon"))
@ -206,6 +207,7 @@ const PureHome = (props) => {
scrollToTop, scrollToTop,
selectedFolderStore, selectedFolderStore,
wsCreatedPDFForm,
}); });
const { showUploadPanel } = useOperations({ const { showUploadPanel } = useOperations({
@ -500,6 +502,7 @@ export default inject(
removeTagsFromRoom, removeTagsFromRoom,
getRooms, getRooms,
scrollToTop, scrollToTop,
wsCreatedPDFForm,
} = filesStore; } = filesStore;
const { updateProfileCulture } = peopleStore.targetUserStore; const { updateProfileCulture } = peopleStore.targetUserStore;
@ -686,6 +689,7 @@ export default inject(
getFolderModel, getFolderModel,
scrollToTop, scrollToTop,
isEmptyGroups, isEmptyGroups,
wsCreatedPDFForm,
}; };
}, },
)(observer(Home)); )(observer(Home));

View File

@ -34,7 +34,7 @@ import {
} from "@docspace/shared/api/files"; } from "@docspace/shared/api/files";
// import { getOperationProgress } from "@docspace/shared/utils/getOperationProgress"; // import { getOperationProgress } from "@docspace/shared/utils/getOperationProgress";
import { toastr } from "@docspace/shared/components/toast"; import { toastr } from "@docspace/shared/components/toast";
import { EDITOR_ID } from "@docspace/shared/constants"; import { CREATED_FORM_KEY, EDITOR_ID } from "@docspace/shared/constants";
import type { import type {
TFile, TFile,
@ -52,6 +52,13 @@ import type { TData } from "@docspace/shared/components/toast/Toast.type";
import { saveAs } from "@/utils"; import { saveAs } from "@/utils";
import type { ConflictStateType } from "@/types"; import type { ConflictStateType } from "@/types";
type SuccessResponseType = {
form: TFile;
message: string;
};
type FaildResponseType = string;
type ResponseType = SuccessResponseType | FaildResponseType;
const DefaultConflictDataDialogState: ConflictStateType = { const DefaultConflictDataDialogState: ConflictStateType = {
visible: false, visible: false,
resolve: () => {}, resolve: () => {},
@ -70,6 +77,12 @@ const hasFileUrl = (arg: object): arg is { data: { url: string } } => {
); );
}; };
const isSuccessResponse = (
res: ResponseType | undefined,
): res is SuccessResponseType => {
return Boolean(res) && typeof res === "object" && "form" in res;
};
const useStartFillingSelectDialog = (fileInfo: TFile | undefined) => { const useStartFillingSelectDialog = (fileInfo: TFile | undefined) => {
// const { t } = useTranslation(["Common"]); // const { t } = useTranslation(["Common"]);
const resolveRef = useRef<(value: string | PromiseLike<string>) => void>(); const resolveRef = useRef<(value: string | PromiseLike<string>) => void>();
@ -179,14 +192,22 @@ const useStartFillingSelectDialog = (fileInfo: TFile | undefined) => {
const fileUrl = await getFileUrl(); const fileUrl = await getFileUrl();
const response = await saveAs( const response = await saveAs<ResponseType>(
fileInfo.title, fileInfo.title,
fileUrl, fileUrl,
selectedItemId, selectedItemId,
false, false,
"createForm",
); );
const [key, value] = response?.split(":") ?? []; if (isSuccessResponse(response)) {
const { form } = response;
sessionStorage.setItem(CREATED_FORM_KEY, JSON.stringify(form));
}
const [key, value] =
typeof response === "string" ? response.split(":") : [];
// await copyToFolder( // await copyToFolder(
// Number(selectedItemId), // Number(selectedItemId),
@ -210,6 +231,7 @@ const useStartFillingSelectDialog = (fileInfo: TFile | undefined) => {
if (key === "error") { if (key === "error") {
toastr.error(value); toastr.error(value);
} else { } else {
requestRunning.current = false;
window.location.replace(url.toString()); window.location.replace(url.toString());
onClose(); onClose();
} }

View File

@ -99,14 +99,15 @@ export const getDataSaveAs = async (params: string) => {
} }
}; };
export const saveAs = ( export const saveAs = <T = string>(
title: string, title: string,
url: string, url: string,
folderId: string | number, folderId: string | number,
openNewTab: boolean, openNewTab: boolean,
action = "create",
) => { ) => {
const options = { const options = {
action: "create", action,
fileuri: url, fileuri: url,
title: title, title: title,
folderid: folderId, folderid: folderId,
@ -115,7 +116,7 @@ export const saveAs = (
const params = toUrlParams(options, true); const params = toUrlParams(options, true);
if (!openNewTab) { if (!openNewTab) {
return getDataSaveAs(params); return getDataSaveAs(params) as Promise<T>;
} else { } else {
const handlerUrl = combineUrl( const handlerUrl = combineUrl(
window.ClientConfig?.proxy?.url, window.ClientConfig?.proxy?.url,

View File

@ -53,6 +53,7 @@ export const ROOM = "room";
export const USERS = "users"; export const USERS = "users";
export const USERS_IN_ROOM = "usersInRoom"; export const USERS_IN_ROOM = "usersInRoom";
export const PDF_FORM_DIALOG_KEY = "pdf_form_dialog"; export const PDF_FORM_DIALOG_KEY = "pdf_form_dialog";
export const CREATED_FORM_KEY = "created_form_key";
export const COUNT_FOR_SHOWING_BAR = 2; export const COUNT_FOR_SHOWING_BAR = 2;
export const PERCENTAGE_FOR_SHOWING_BAR = 90; export const PERCENTAGE_FOR_SHOWING_BAR = 90;