Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jblayone committed Apr 7, 2022
1 parent e981993 commit 596e12d
Show file tree
Hide file tree
Showing 67 changed files with 740 additions and 879 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@
],
"moduleDirectories": [
"node_modules",
"release/app/node_modules"
"release/app/node_modules",
"src"
],
"testPathIgnorePatterns": [
"release/app/dist"
Expand Down
4 changes: 2 additions & 2 deletions release/app/package-lock.json

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

2 changes: 1 addition & 1 deletion release/app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "community-calendar-manager",
"version": "0.0.1",
"version": "0.0.2",
"description": "A community calendar fundraiser manager",
"main": "./dist/main/main.js",
"author": {
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/App.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import '@testing-library/jest-dom';
import { render } from '@testing-library/react';
import { Provider } from 'react-redux';
import store from '../renderer/store';
import store from '../renderer/redux/store';
import App from '../renderer/App';

describe('App', () => {
Expand Down
62 changes: 38 additions & 24 deletions src/renderer/common/constants.ts → src/main/common/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
export const compatibleFileVersion = '0.0.1';
export const fileVersion = '0.0.1';
export const fileVersion = '0.0.2';

export const months = [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December',
];

export const shortMonths = [
'jan',
'feb',
'mar',
'apr',
'may',
'jun',
'jul',
'aug',
'sep',
'oct',
'nov',
'dec',
];

export const provinces = [
{ value: 'SK', label: 'Saskatchewan' },
Expand All @@ -17,28 +46,7 @@ export const provinces = [
{ value: 'YT', label: 'Yukon' },
];

export const options = [
{ value: 'A', label: 'Anniversary' },
{ value: 'B', label: 'Birthday' },
{ value: 'M', label: 'Memoriam' },
];

export const monthNames = [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December',
];

export const months = [
export const calendarEventMonths = [
{ value: 'January', label: 'January' },
{ value: 'February', label: 'February' },
{ value: 'March', label: 'March' },
Expand All @@ -52,3 +60,9 @@ export const months = [
{ value: 'November', label: 'November' },
{ value: 'December', label: 'December' },
];

export const calendarEventOptions = [
{ value: 'A', label: 'Anniversary' },
{ value: 'B', label: 'Birthday' },
{ value: 'M', label: 'Memoriam' },
];
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import {
BusinessCardModel,
ClubCardModel,
FamilyCardModel,
} from 'renderer/models/redux-models';
} from '../models/calendar-model';

export const defaultFamily: FamilyCardModel = {
export const EmptyFamilyCard: FamilyCardModel = {
id: '',
family_name: '',
contacts: [
Expand Down Expand Up @@ -41,7 +41,7 @@ export const defaultFamily: FamilyCardModel = {
},
};

export const defaultBusiness: BusinessCardModel = {
export const EmptyBusinessCard: BusinessCardModel = {
id: '',
business_name: '',
contacts: [
Expand Down Expand Up @@ -78,7 +78,7 @@ export const defaultBusiness: BusinessCardModel = {
},
};

export const defaultClub: ClubCardModel = {
export const EmptyClubCard: ClubCardModel = {
id: '',
club_name: '',
contacts: [
Expand Down
30 changes: 30 additions & 0 deletions src/main/common/form-schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import * as yup from 'yup';

const schema = yup.object().shape({
family_name: yup.string().required(),
contacts: yup.array().of(
yup.object().shape({
firstName: yup.string().required(),
lastName: yup.string().required(),
})
),
contactDetails: yup.object().shape({
homePhone: yup.string(),
workPhone: yup.string(),
email: yup.string(),
}),
address: yup.object().shape({
addressLine: yup.string().required(),
streetName: yup.string().required(),
city: yup.string().required(),
province: yup.string().required(),
postalCode: yup.string().required(),
}),
order: yup.object().shape({
amountOfCalendarsPurchased: yup.string().required(),
amountDonated: yup.string(),
didDonated: yup.boolean(),
}),
});

export default schema;
13 changes: 13 additions & 0 deletions src/main/common/route-paths.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const routePaths = {
welcome: '/',
enterPassword: '/password',
makeCalendar: '/new',
resetPassword: '/password/reset',
home: '/dashboard',
familyCards: '/dashboard/cards/family',
businessCards: '/dashboard/cards/family',
clubCards: '/dashboard/cards/club',
list: '/dashboard/list',
};

export default routePaths;
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export enum IntroScreenTypes {
Welcome = 'welcome',
EnterPassword = 'enterPassword',
MakePassword = 'makePassword',
ResetPassword = 'resetPassword',
EnterPassword = 'Enter Password',
MakeCalendar = 'Make Calendar',
ResetPassword = 'Reset Password',
}

export enum DashboardScreensTypes {
Analytics = 'Analytics',
Home = 'Home',
FamilyCards = 'Family Cards',
BusinessCards = 'Business Cards',
ClubCards = 'Club Cards',
Expand Down
61 changes: 28 additions & 33 deletions src/main/ipc/file-manager.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,31 @@
import { ipcMain } from 'electron';
import { months } from '../common/constants';
import {
EmptyBusinessCard,
EmptyClubCard,
EmptyFamilyCard,
} from '../common/empty-cards';
import { LegacyFamilyModels } from '../models/legacy-calendar-model';
import CalendarModel, {
BusinessCardModel,
CalendarEventModel,
CalendarModel,
FamilyCardModel,
} from '../models/calendar-model';
import {
EncryptedFileModel,
ImportCalendarModel,
} from 'renderer/models/redux-models';
import { LegacyFamilyModels } from 'renderer/models/legacy-models';
import { defaultBusiness, defaultClub, defaultFamily } from './models/defaults';
import { ReadFileType, WriteFileType } from './types/file-manager-types';
import { EncryptedFileType, encrypt, decrypt } from './service/encryption';
ReadFileModel,
WriteCalendarFileModel,
} from '../models/ipc-models';
import { encrypt, decrypt } from './service/encryption';
import { familyCardsPDF, businessCardsPDF, clubCardsPDF } from './service/pdf';

const fs = require('fs');

const monthNames = [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December',
];

function readCalendarFile(fileInfo: ReadFileType): ImportCalendarModel {
function readCalendarFile(fileInfo: ReadFileModel): ImportCalendarModel {
try {
const rawData: string = fs.readFileSync(fileInfo.path, 'utf8');
const encryptedData: EncryptedFileType = JSON.parse(rawData);
const encryptedData: EncryptedFileModel = JSON.parse(rawData);

const decryptedData: string = decrypt(encryptedData, fileInfo.password);

Expand All @@ -56,7 +49,7 @@ function readCalendarFile(fileInfo: ReadFileType): ImportCalendarModel {
}
}

function readLegacyCalendarFile(fileInfo: ReadFileType): ImportCalendarModel {
function readLegacyCalendarFile(fileInfo: ReadFileModel): ImportCalendarModel {
try {
const data: LegacyFamilyModels[] = JSON.parse(
fs.readFileSync(fileInfo.path, 'utf8')
Expand All @@ -72,7 +65,7 @@ function readLegacyCalendarFile(fileInfo: ReadFileType): ImportCalendarModel {
type: data[x].calendar[y].type,
date: {
month: `${
monthNames[parseInt(data[x].calendar[y].date.slice(5, 7), 10) - 1]
months[parseInt(data[x].calendar[y].date.slice(5, 7), 10) - 1]
}`,
day: `${data[x].calendar[y].date.slice(8, 10)}`,
},
Expand Down Expand Up @@ -148,11 +141,11 @@ function readLegacyCalendarFile(fileInfo: ReadFileType): ImportCalendarModel {
dateCreated: '',
dateModified: '',
version: '',
defaultFamilyCard: defaultFamily,
defaultFamilyCard: EmptyFamilyCard,
familyCards,
defaultBusinessCard: defaultBusiness,
defaultBusinessCard: EmptyBusinessCard,
businessCards,
defaultClubCard: defaultClub,
defaultClubCard: EmptyClubCard,
clubCards: [],
};

Expand All @@ -168,11 +161,13 @@ function readLegacyCalendarFile(fileInfo: ReadFileType): ImportCalendarModel {
}
}

function writeCalendarFile(fileInfo: WriteFileType): ImportCalendarModel {
function writeCalendarFile(
fileInfo: WriteCalendarFileModel
): ImportCalendarModel {
try {
const stringData: string = JSON.stringify(fileInfo.calendar);

const encryptedData: EncryptedFileType = encrypt(
const encryptedData: EncryptedFileModel = encrypt(
stringData,
fileInfo.password
);
Expand All @@ -192,7 +187,7 @@ function writeCalendarFile(fileInfo: WriteFileType): ImportCalendarModel {
});
}

function writeFamilyCardPDF(fileInfo: WriteFileType): boolean {
function writeFamilyCardPDF(fileInfo: WriteCalendarFileModel): boolean {
try {
const { familyCards } = fileInfo.calendar;

Expand All @@ -205,7 +200,7 @@ function writeFamilyCardPDF(fileInfo: WriteFileType): boolean {
}
}

function writeBusinessCardPDF(fileInfo: WriteFileType): boolean {
function writeBusinessCardPDF(fileInfo: WriteCalendarFileModel): boolean {
try {
const { businessCards } = fileInfo.calendar;

Expand All @@ -218,7 +213,7 @@ function writeBusinessCardPDF(fileInfo: WriteFileType): boolean {
}
}

function writeClubCardPDF(fileInfo: WriteFileType): boolean {
function writeClubCardPDF(fileInfo: WriteCalendarFileModel): boolean {
try {
const { clubCards } = fileInfo.calendar;

Expand Down
10 changes: 3 additions & 7 deletions src/main/ipc/service/encryption.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
import * as crypto from 'crypto';
import { EncryptedFileModel } from 'main/models/ipc-models';

const algorithm = 'aes-256-ctr';
const iv = crypto.randomBytes(16);

export interface EncryptedFileType {
iv: string;
encryptedData: string;
}

export function encrypt(data: string, pass: string): EncryptedFileType {
export function encrypt(data: string, pass: string): EncryptedFileModel {
const password = crypto.scryptSync(pass, 'salt', 32);
const cipher = crypto.createCipheriv(algorithm, Buffer.from(password), iv);
let encrypted = cipher.update(data);
encrypted = Buffer.concat([encrypted, cipher.final()]);
return { iv: iv.toString('hex'), encryptedData: encrypted.toString('hex') };
}

export function decrypt(data: EncryptedFileType, pass: string): string {
export function decrypt(data: EncryptedFileModel, pass: string): string {
const password = crypto.scryptSync(pass, 'salt', 32);
const ivFile = Buffer.from(data.iv, 'hex');
const encryptedText = Buffer.from(data.encryptedData, 'hex');
Expand Down
Loading

0 comments on commit 596e12d

Please sign in to comment.