From 6a65b66cc3fb1057c9cbe2799dcf6cbeb1d87962 Mon Sep 17 00:00:00 2001 From: Dawid Tarasiuk Date: Wed, 27 May 2020 14:50:11 +0200 Subject: [PATCH] Update jobs model types --- src/@sdk/helpers/LocalStorageHandler/types.ts | 14 +++++++-- src/@sdk/jobs/JobsManager.ts | 30 +++++++++++-------- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/@sdk/helpers/LocalStorageHandler/types.ts b/src/@sdk/helpers/LocalStorageHandler/types.ts index f45854edf2..9a6c51fc0d 100644 --- a/src/@sdk/helpers/LocalStorageHandler/types.ts +++ b/src/@sdk/helpers/LocalStorageHandler/types.ts @@ -3,7 +3,8 @@ import { Checkout_lines_variant_attributes, Checkout_lines_variant_pricing, Checkout_lines_variant_product, -} from "../../fragments/gqlTypes/Checkout"; +} from "@sdk/fragments/gqlTypes/Checkout"; +import { IQueuedJobs } from "@sdk/jobs/QueuedJobs"; export enum LocalStorageItems { JOB_QUEUE_CHECKOUT = "job_queueCheckout", @@ -124,7 +125,16 @@ export interface IOrderModel { number?: string | null; } -export type IJobsModel = Record>; +export type IJobsGroupModel = Record< + keyof IQueuedJobs[G], + boolean +>; + +type IQueuedJobsState = { + [P in keyof T]?: Partial>; +}; + +export type IJobsModel = IQueuedJobsState; export interface ILocalStorageHandler { getCheckout(): ICheckoutModel | null; diff --git a/src/@sdk/jobs/JobsManager.ts b/src/@sdk/jobs/JobsManager.ts index b7a5d63683..baa8852736 100644 --- a/src/@sdk/jobs/JobsManager.ts +++ b/src/@sdk/jobs/JobsManager.ts @@ -153,7 +153,7 @@ export class JobsManager { const jobGroupString = jobGroup.toString(); const jobNameString = jobName.toString(); - const jobGroupObject = jobs ? jobs[jobGroupString] : null; + const jobGroupObject = jobs ? jobs[jobGroup] : null; this.localStorageHandler.setJobs({ ...jobs, @@ -169,18 +169,22 @@ export class JobsManager { if (jobs) { Object.keys(jobs).forEach(jobGroupString => { - const jobGroup = jobs[jobGroupString]; - - Object.keys(jobGroup).forEach(jobNameString => { - const jobNameState = jobGroup[jobNameString]; - - if (jobNameState) { - this.addToQueue( - jobGroupString as keyof IQueuedJobs, - jobNameString as keyof QueuedJobs[keyof IQueuedJobs] - ); - } - }); + const jobGroupKey = jobGroupString as keyof IQueuedJobs; + const jobGroup = jobs[jobGroupKey]; + + if (jobGroup) { + Object.keys(jobGroup).forEach(jobNameString => { + const jobNameKey = jobNameString as keyof QueuedJobs[keyof IQueuedJobs]; + const jobNameState = jobGroup[jobNameKey]; + + if (jobNameState) { + this.addToQueue( + jobGroupString as keyof IQueuedJobs, + jobNameString as keyof QueuedJobs[keyof IQueuedJobs] + ); + } + }); + } }); } }