Skip to content
Open
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
31 changes: 19 additions & 12 deletions Govt-Billing-React/src/components/Menu/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const Menu: React.FC<{
const [showAlert4, setShowAlert4] = useState(false);
const [showToast1, setShowToast1] = useState(false);
const [toastMessage, setToastMessage] = useState("");

/* Utility functions */
const _validateName = async (filename) => {
filename = filename.trim();
Expand Down Expand Up @@ -62,23 +63,29 @@ const Menu: React.FC<{
printer.print(AppGeneral.getCurrentHTMLContent());
} else {
const content = AppGeneral.getCurrentHTMLContent();
// useReactToPrint({ content: () => content });
const printWindow = window.open("/printwindow", "Print Invoice");
printWindow.document.write(content);
printWindow.print();
}
};

const doSave = () => {
if (props.file === "default") {
setShowAlert1(true);
return;
}
const content = encodeURIComponent(AppGeneral.getSpreadsheetContent());
const content = AppGeneral.getSpreadsheetContent();
if (!content || content.trim() === "" || content === "{}") {
setToastMessage("Cannot save an empty invoice!");
setShowToast1(true);
return;
}
const encodedContent = encodeURIComponent(content);
const data = props.store._getFile(props.file);
const file = new File(
(data as any).created,
new Date().toString(),
content,
encodedContent,
props.file,
props.bT
);
Expand All @@ -88,22 +95,22 @@ const Menu: React.FC<{
};

const doSaveAs = async (filename) => {
// event.preventDefault();
if (filename) {
// console.log(filename, _validateName(filename));
if (await _validateName(filename)) {
// filename valid . go on save
const content = encodeURIComponent(AppGeneral.getSpreadsheetContent());
// console.log(content);
const content = AppGeneral.getSpreadsheetContent();
if (!content || content.trim() === "" || content === "{}") {
setToastMessage("Cannot save an empty invoice!");
setShowToast1(true);
return;
}
const encodedContent = encodeURIComponent(content);
const file = new File(
new Date().toString(),
new Date().toString(),
content,
encodedContent,
filename,
props.bT
);
// const data = { created: file.created, modified: file.modified, content: file.content, password: file.password };
// console.log(JSON.stringify(data));
props.store._saveFile(file);
props.updateSelectedFile(filename);
setShowAlert4(true);
Expand Down Expand Up @@ -240,4 +247,4 @@ const Menu: React.FC<{
);
};

export default Menu;
export default Menu;