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

Feat(contacted people) import data from excel #345

Merged
merged 15 commits into from
Oct 11, 2020
139 changes: 136 additions & 3 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"redux": "^4.0.5",
"redux-thunk": "^2.3.0",
"sweetalert2": "^9.17.1",
"xlsx": "^0.16.7",
"yup": "^0.29.3"
},
"scripts": {
Expand Down
4 changes: 4 additions & 0 deletions client/src/Utils/vendor/underscoreReplacement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,7 @@ export function throttle<T extends Function>(func: T, wait: number, options?:Th

return throttled;
}

export const isObjectEmpty = (element: any): boolean => {
return Object.keys(element).length === 0 && element.constructor === Object
};
RoeiRom marked this conversation as resolved.
Show resolved Hide resolved
31 changes: 31 additions & 0 deletions client/src/Utils/vendor/useExcel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import XLSX from 'xlsx';

const useExcel = () => {
const baseDate = new Date(1899, 11, 30, 0, 0, 0);
const dnthresh = baseDate.getTime() + (new Date().getTimezoneOffset() - baseDate.getTimezoneOffset()) * 60000;

const day_ms = 24 * 60 * 60 * 1000;
const days_1462_ms = 1462 * day_ms;
RoeiRom marked this conversation as resolved.
Show resolved Hide resolved

const datenum = (v: Date, date1904: boolean) => {
RoeiRom marked this conversation as resolved.
Show resolved Hide resolved
RoeiRom marked this conversation as resolved.
Show resolved Hide resolved
let epoch = v.getTime();
if (date1904) {
epoch -= days_1462_ms;
}
return (epoch - dnthresh) / day_ms;
};

const fixImportedDate = (date1904: boolean) => (date: Date) => {
// Convert JS Date back to Excel date code and parse them using SSF module.
const parsed = XLSX.SSF.parse_date_code(datenum(date, false), {date1904});
return new Date(`${parsed.y}-${parsed.m}-${parsed.d}`);
};

return {
read: XLSX.read,
sheet_to_json: XLSX.utils.sheet_to_json,
fixImportedDate
}
};

export default useExcel;
10 changes: 10 additions & 0 deletions client/src/commons/CustomSwal/CustomSwalStyles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { makeStyles } from '@material-ui/styles';

const useStyles = makeStyles({
swalTitle: {
fontSize: '1.5vw',
fontFamily: 'Assistant',
},
});

export default useStyles;
29 changes: 29 additions & 0 deletions client/src/commons/CustomSwal/useCustomSwal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import Swal, {SweetAlertIcon, SweetAlertOptions} from 'sweetalert2';
import useStyles from './CustomSwalStyles';

const useCustomSwal = () => {
const classes = useStyles();

const alert = (title: string,icon: SweetAlertIcon, options?: SweetAlertOptions) =>
Swal.fire({
title,
icon,
customClass: {
title: classes.swalTitle
},
...options
});

const alertError = (title: string, options?: SweetAlertOptions) => alert(title, 'error', options);
const alertWarning = (title: string, options?: SweetAlertOptions) => alert(title, 'warning', options);
const alertSuccess = (title: string, options?: SweetAlertOptions) => alert(title, 'success', options);

return {
alertError,
alertWarning,
alertSuccess,
}

};

export default useCustomSwal;
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ const useContactQuestioning = (parameters: useContactQuestioningParameters): use
additionalPhoneNumber: contact.personByPersonInfo.additionalPhoneNumber,
gender: contact.personByPersonInfo.gender,
contactDate: contact.contactEventByContactEvent.startTime,
contactEvent: contact.contactEventByContactEvent.id,
contactType: contact.contactType,
cantReachContact: contact.cantReachContact ? contact.cantReachContact : false,
extraInfo: contact.extraInfo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const ContactDateCard: React.FC<Props> = (props: Props) => {
<Collapse in={areInteractionsOpen}>
{interactions?.map(interaction =>
<InteractionCard
loadInteractions={props.loadInteractions}
RoeiRom marked this conversation as resolved.
Show resolved Hide resolved
onEditClick={() => onEditClick(interaction)}
onDeleteClick={() => interaction.id && onDeleteClick(interaction.id)}
key={interaction.id ? interaction.id : interaction.startTime.getTime()} interaction={interaction} />
Expand All @@ -65,6 +66,7 @@ interface Props {
createNewInteractionEvent: () => void;
onEditClick: (interaction: Interaction) => void;
onDeleteClick: (contactEventId: number) => void;
loadInteractions: () => void;
};

export default ContactDateCard;
Loading