Skip to content

Commit

Permalink
Merge pull request #52 from Laserfiche/alex/popup-login
Browse files Browse the repository at this point in the history
Alex/popup login
  • Loading branch information
alexgomezlf authored Oct 16, 2023
2 parents 3f5ae05 + 821e22d commit 55f4463
Show file tree
Hide file tree
Showing 13 changed files with 719 additions and 212 deletions.
19 changes: 19 additions & 0 deletions src/Utils/Funcs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { UrlUtils } from '@laserfiche/lf-js-utils';
import { WFieldType } from '@laserfiche/lf-repository-api-client';
import { BaseComponentContext } from '@microsoft/sp-component-base';
import { SPDEVMODE_LOCAL_STORAGE_KEY } from '../webparts/constants';

Expand Down Expand Up @@ -46,3 +47,21 @@ export function getRegion(): string {
const region = spDevModeTrue ? 'a.clouddev.laserfiche.com' : 'laserfiche.com';
return region;
}

export function getCorrespondingTypeFieldName(fieldType: WFieldType): string {
switch (fieldType) {
case WFieldType.Date:
case WFieldType.List:
case WFieldType.Time:
case WFieldType.Number:
return fieldType;
case WFieldType.DateTime:
return 'Date/Time';
case WFieldType.String:
return 'Text';
case WFieldType.ShortInteger:
return 'Integer';
case WFieldType.LongInteger:
return 'Long Integer';
}
}
109 changes: 109 additions & 0 deletions src/extensions/savetoLaserfiche/CommonDialogs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,112 @@ export function SavedToLaserficheSuccessDialogButtons(props: {
</>
);
}

export function MessageDialog(props: {
title: string;
message: string;
clickOkay: () => void;
}): JSX.Element {
return (
<div className='modal-dialog modal-dialog-centered'>
<div className={`modal-content ${styles.wrapper}`}>
<div className={styles.header}>
<h5 className='modal-title' id='ModalLabel'>
{props.title}
</h5>
</div>
<div className={styles.contentBox}>{props.message}</div>
<div className={styles.footer}>
<button
type='button'
className='lf-button primary-button'
data-dismiss='modal'
onClick={props.clickOkay}
>
Okay
</button>
</div>
</div>
</div>
);
}

const createPromise: () => Promise<boolean>[] = () => {
let resolver;
return [
new Promise<boolean>((resolve, reject) => {
resolver = resolve;
}),
resolver,
];
};

export const useConfirm: () => [
(text: string) => Promise<unknown>,
(props: { cancelButtonText: string }) => JSX.Element
] = () => {
const [open, setOpen] = React.useState(false);
const [resolver, setResolver] = React.useState({ resolve: null });
const [label, setLabel] = React.useState('');

const getConfirmation: (text: string) => Promise<boolean> = async (
text: string
) => {
setLabel(text);
setOpen(true);
const [promise, resolve] = await createPromise();
setResolver({ resolve: resolve });
return promise;
};

const onClick: (status: boolean) => Promise<void> = async (
status: boolean
) => {
setOpen(false);
resolver.resolve(status);
};

const Confirmation: (props: {
cancelButtonText: string;
}) => JSX.Element = (props: { cancelButtonText: string }) => (
<>
{open && (
<>
<div className={`modal-header ${styles.header}`}>
<div className='modal-title' id='ModalLabel'>
<div className={styles.logoHeader}>
<img
src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAALQAAAC0CAMAAAAKE/YAAAAAUVBMVEXSXyj////HYzL/+/T/+Or/9d+yaUa9ZT2yaUj/9OG7Zj3SXybRYCj/+/b///3LYS/OYCvEZDS2aEL/89jAZTnMYS3/8dO7Zzusa02+ZTn/78wyF0DsAAABnUlEQVR4nO3ci26CMABGYQcoLRS5OTf2/g86R+KSLYUm2vxcPB8RTYzxkADRajkcAAAAAAAAAADYgbJcusCvqdtLnhfeJR/a96X7vOriarNJ/cUtHeiTnI7p26TsY+XRZ190sXSfVyA6X7rP6xZdzeweREeTGDt3IBIdTeCUR3Q0wQOxLNf3CWSr0ZvcPYiWIFqFaBWiVYhWIVqFaBWiVYhWIVqFaBWiVYhWIVqFaBWiVYhWIVqFaBWiVYhWIVqFaBWiVYhWIVqFaBWiVYhWIVqFaBWiVV4zeok/379m9BL2HO1Ckymlky0jRQc3Kqoou4f6YHzdaLX56PRzak757/JjfDS0dbOK6HM6Paf8P3st6lVE/9mAwPOpNcnqokOIJppoookmmmiiiSaaaKKJ3k30OfTFdU3RXZ+lT6qq6rbO+k4VXQ9fvT2OrH30Zo+3u/5rUI17NO3QmdPImIduxoyrUze0khEm5w6uqZNIRKNi91Hl5661dH+tdow6wts5J//BaJPRwH6IT1NxbDJ6vVc+nrXJaAAAAADALn0DBosqnCStFi4AAAAASUVORK5CYII='
width='30'
height='30'
/>
<span className={styles.paddingLeft}>
Document already exists
</span>
</div>
</div>
</div>
<div className={`modal-body ${styles.contentBox}`}>
<span>{label}</span>
</div>
<div className={`modal-footer ${styles.footer}`}>
<button
className={`lf-button primary-button ${styles.actionButton}`}
onClick={() => onClick(true)}
>
Continue
</button>
<button
className='lf-button sec-button'
onClick={() => onClick(false)}
>
{props.cancelButtonText}
</button>
</div>
</>
)}
</>
);

return [getConfirmation, Confirmation];
};
33 changes: 7 additions & 26 deletions src/extensions/savetoLaserfiche/GetDocumentDataDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -416,32 +416,13 @@ function GetDocumentDialogData(props: {
// automatically trims length to match constraint
spDocFieldValue = spDocFieldValue.slice(0, lfField.length);
}
} else if (lfField.fieldType === WFieldType.ShortInteger) {
const extractOnlyNumbers = spDocFieldValue.replace(/[^0-9]/g, '');
const valueAsNumber = Number.parseInt(extractOnlyNumbers, 10);
if (valueAsNumber > 64999 || valueAsNumber < 0) {
// TODO invalid field -- should it truncate???
spDocFieldValue = '';
} else {
spDocFieldValue = extractOnlyNumbers;
}
} else if (lfField.fieldType === WFieldType.LongInteger) {
const extractOnlyNumbers = spDocFieldValue.replace(/[^0-9]/g, '');
const valueAsNumber = Number.parseInt(extractOnlyNumbers, 10);
if (valueAsNumber > 3999999999 || valueAsNumber < 0) {
// TODO invalid field -- should it truncate???
spDocFieldValue = '';
} else {
spDocFieldValue = extractOnlyNumbers;
}
} else if (lfField.fieldType === WFieldType.Number) {
const valueRemoveNonNumbers = spDocFieldValue.replace(/[^0-9.]/g, '');
if (!isNaN(Number.parseFloat(valueRemoveNonNumbers))) {
spDocFieldValue = valueRemoveNonNumbers;
} else {
// TODO invalid field -- should it truncate???
spDocFieldValue = '';
}
} else if (
lfField.fieldType === WFieldType.ShortInteger ||
lfField.fieldType === WFieldType.LongInteger ||
lfField.fieldType === WFieldType.Number
) {
const extractOnlyNumbers = spDocFieldValue.replace(/[^0-9.]/g, '');
spDocFieldValue = extractOnlyNumbers;
}
return spDocFieldValue;
}
Expand Down
Loading

0 comments on commit 55f4463

Please sign in to comment.