Skip to content

Commit

Permalink
Fix spacing formating (#465)
Browse files Browse the repository at this point in the history
  • Loading branch information
allthesignals authored Feb 21, 2025
1 parent 39acb23 commit c2e00a6
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 144 deletions.
57 changes: 28 additions & 29 deletions app/app/javascript/adapters/ModalAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,41 @@
import type { RequestData, ModalAdapterArgs } from "./ModalAdapter.types.ts";

export abstract class ModalAdapter {
requestData?: RequestData;
successCallback?: Function;
exitCallback?: Function;
requestData?: RequestData;
successCallback?: Function;
exitCallback?: Function;

abstract open(): void;
abstract onEvent(eventName: string, eventPayload: any): void;
load() {};
abstract open(): void;
abstract onEvent(eventName: string, eventPayload: any): void;
load() {};

constructor() {
this.load();
}

init(args: ModalAdapterArgs) {
constructor() {
this.load();
}

if (args.onSuccess) {
this.successCallback = args.onSuccess;
}
init(args: ModalAdapterArgs) {
if (args.onSuccess) {
this.successCallback = args.onSuccess;
}

if (args.onExit) {
this.exitCallback = args.onExit;
if (args.onExit) {
this.exitCallback = args.onExit;

}
if (args.requestData) {
this.requestData = args.requestData;
}
}
}
if (args.requestData) {
this.requestData = args.requestData;
}
}

async onExit(eventPayload: any) {
if (this.exitCallback) {
this.exitCallback();
}
async onExit(eventPayload: any) {
if (this.exitCallback) {
this.exitCallback();
}
}

async onSuccess(eventPayload: any) {
if (this.successCallback) {
this.successCallback();
}
async onSuccess(eventPayload: any) {
if (this.successCallback) {
this.successCallback();
}
}
}
18 changes: 9 additions & 9 deletions app/app/javascript/adapters/ModalAdapter.types.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
export interface ModalAdapterArgs {
requestData: RequestData;
onSuccess?: Function;
onExit?: Function;
requestData: RequestData;
onSuccess?: Function;
onExit?: Function;
}

export interface RequestData {
responseType: string;
id: string;
isDefaultOption: boolean;
providerName: string;
name: string;
}
responseType: string;
id: string;
isDefaultOption: boolean;
providerName: string;
name: string;
}
157 changes: 78 additions & 79 deletions app/app/javascript/adapters/PinwheelModalAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,92 +4,91 @@ import { getDocumentLocale } from "../utilities/getDocumentLocale.js";
import { ModalAdapter } from "./ModalAdapter.js";

export default class PinwheelModalAdapter extends ModalAdapter {
Pinwheel: Pinwheel;
Pinwheel: Pinwheel;

async load() {
this.Pinwheel = await new Promise((resolve, reject) => {
loadScript('https://cdn.getpinwheel.com/pinwheel-v3.0.js', (err, script) => {
if (err) {
reject(err);
} else {
resolve(Pinwheel);
}
});
})
}

async open() {
const locale = getDocumentLocale();
if (this.requestData) {
await trackUserAction("ApplicantSelectedEmployerOrPlatformItem", {
item_type: this.requestData.responseType,
item_id: this.requestData.id,
item_name: this.requestData.name,
is_default_option: this.requestData.isDefaultOption,
provider_name: this.requestData.providerName,
locale
})
async load() {
this.Pinwheel = await new Promise((resolve, reject) => {
loadScript('https://cdn.getpinwheel.com/pinwheel-v3.0.js', (err, script) => {
if (err) {
reject(err);
} else {
resolve(Pinwheel);
}
});
})
}

async open() {
const locale = getDocumentLocale();

const { token } = await fetchToken(this.requestData.responseType, this.requestData.id, locale);
if (this.requestData) {
await trackUserAction("ApplicantSelectedEmployerOrPlatformItem", {
item_type: this.requestData.responseType,
item_id: this.requestData.id,
item_name: this.requestData.name,
is_default_option: this.requestData.isDefaultOption,
provider_name: this.requestData.providerName,
locale
});

return this.Pinwheel.open({
linkToken: token,
onSuccess: this.onSuccess.bind(this),
onExit: this.onExit.bind(this),
onEvent: this.onEvent.bind(this),
});
}
const { token } = await fetchToken(this.requestData.responseType, this.requestData.id, locale);

return this.Pinwheel.open({
linkToken: token,
onSuccess: this.onSuccess.bind(this),
onExit: this.onExit.bind(this),
onEvent: this.onEvent.bind(this),
});
}
}


async onSuccess(eventPayload: LinkResult) {
await trackUserAction("PinwheelSuccess", {
account_id: eventPayload.accountId,
platform_id: eventPayload.platformId
})
if (this.successCallback) {
this.successCallback(eventPayload.accountId);
}
async onSuccess(eventPayload: LinkResult) {
await trackUserAction("PinwheelSuccess", {
account_id: eventPayload.accountId,
platform_id: eventPayload.platformId
})
if (this.successCallback) {
this.successCallback(eventPayload.accountId);
}
}

onEvent(eventName: string, eventPayload: any) {
switch (eventName) {
case "screen_transition":
onScreenTransitionEvent(eventPayload.screenName);
break;
case 'login_attempt':
trackUserAction("PinwheelAttemptLogin", {})
break;
case 'error':
const { type, code, message } = eventPayload
trackUserAction("PinwheelError", { type, code, message })
break;
case 'exit':
trackUserAction("PinwheelCloseModal", {})
break;

}

onEvent(eventName: string, eventPayload: any) {
switch (eventName) {
case "screen_transition":
onScreenTransitionEvent(eventPayload.screenName);
break;
case 'login_attempt':
trackUserAction("PinwheelAttemptLogin", {})
break;
case 'error':
const { type, code, message } = eventPayload
trackUserAction("PinwheelError", { type, code, message })
break;
case 'exit':
trackUserAction("PinwheelCloseModal", {})
break;
}

function onScreenTransitionEvent(screenName : string) {
switch (screenName) {
case "LOGIN":
trackUserAction("PinwheelShowLoginPage", {
screen_name: screenName,
employer_name: eventPayload.selectedEmployerName,
platform_name: eventPayload.selectedPlatformName
});
break;
case "PROVIDER_CONFIRMATION":
trackUserAction("PinwheelShowProviderConfirmationPage", {});
break;
case "SEARCH_DEFAULT":
trackUserAction("PinwheelShowDefaultProviderSearch", {});
break;
case "EXIT_CONFIRMATION":
trackUserAction("PinwheelAttemptClose", {});
break;
}
}
function onScreenTransitionEvent(screenName : string) {
switch (screenName) {
case "LOGIN":
trackUserAction("PinwheelShowLoginPage", {
screen_name: screenName,
employer_name: eventPayload.selectedEmployerName,
platform_name: eventPayload.selectedPlatformName
});
break;
case "PROVIDER_CONFIRMATION":
trackUserAction("PinwheelShowProviderConfirmationPage", {});
break;
case "SEARCH_DEFAULT":
trackUserAction("PinwheelShowDefaultProviderSearch", {});
break;
case "EXIT_CONFIRMATION":
trackUserAction("PinwheelAttemptClose", {});
break;
}
}
}
}
}
31 changes: 15 additions & 16 deletions app/app/javascript/types/Pinwheel.d.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
type LinkResult = {
accountId: string;
platformId: string;
job: string;
params: {
amount?: { value: number, unit: '%' | '$' }
}
accountId: string;
platformId: string;
job: string;
params: {
amount?: { value: number, unit: '%' | '$' }
}
}

type PinwheelError = { type: string; code: string; message: string, pendingRetry: boolean }


type InitializationParams = {
linkToken: string;
onLogin?: (result: { accountId: string, platformId: string }) => void;
onSuccess?: (result: LinkResult) => void;
onError?: (error: PinwheelError) => void;
onExit?: (error?: PinwheelError) => void;
onEvent?: (name: string, payload: EventPayload) => void;
};
linkToken: string;
onLogin?: (result: { accountId: string, platformId: string }) => void;
onSuccess?: (result: LinkResult) => void;
onError?: (error: PinwheelError) => void;
onExit?: (error?: PinwheelError) => void;
onEvent?: (name: string, payload: EventPayload) => void;
};

type Pinwheel = {
open: (params : InitializationParams) => void;
close: () => void;
open: (params : InitializationParams) => void;
close: () => void;
}
4 changes: 2 additions & 2 deletions app/app/javascript/types/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
declare global {
var Pinwheel: Pinwheel;
var Pinwheel: Pinwheel;
}

export {};
export {};
7 changes: 3 additions & 4 deletions app/app/javascript/types/load-script.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
declare module "load-script" {
type loadScriptCallback = (error : object, script: object) => void;
function loadScript(url: string, callback: loadScriptCallback): void;
export = loadScript;
type loadScriptCallback = (error : object, script: object) => void;
function loadScript(url: string, callback: loadScriptCallback): void;
export = loadScript;
}

9 changes: 4 additions & 5 deletions app/app/javascript/utilities/createModalAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import PinwheelModalAdapter from "../adapters/PinwheelModalAdapter.js";


export const createModalAdapter = (providerName: string) => {
switch (providerName) {
default:
return new PinwheelModalAdapter();
}
switch (providerName) {
default:
return new PinwheelModalAdapter();
}
};

0 comments on commit c2e00a6

Please sign in to comment.