apps/web: add getCurrentDateString

This commit is contained in:
vchikalkin 2024-04-23 14:13:53 +03:00
parent 9c3f2bbd78
commit 83031218ea
14 changed files with 34 additions and 30 deletions

View File

@ -4,7 +4,7 @@ import type { Row } from '../types';
import type { RequestEltKasko, RequestEltOsago } from '@/api/elt/types';
import * as CRMTypes from '@/graphql/crm.types';
import type { ProcessContext } from '@/process/types';
import { getCurrentISODate } from '@/utils/date';
import { getCurrentDateString } from '@/utils/date';
import dayjs from 'dayjs';
import { first, sort } from 'radash';
@ -12,7 +12,7 @@ export async function makeOwnOsagoRequest(
{ store, apolloClient }: Pick<ProcessContext, 'apolloClient' | 'store'>,
row: Row
): Promise<NonNullable<CRMTypes.GetOsagoAddproductTypesQuery['evo_addproduct_types']>[number]> {
const currentDate = getCurrentISODate();
const currentDate = getCurrentDateString();
const {
data: { evo_addproduct_types },

View File

@ -4,7 +4,7 @@ import type { ProcessContext } from '../types';
import { createValidationSchema } from './validation';
import { selectRequirementTelematic } from '@/config/default-options';
import * as CRMTypes from '@/graphql/crm.types';
import { getCurrentISODate } from '@/utils/date';
import { getCurrentDateString } from '@/utils/date';
import { normalizeOptions } from '@/utils/entity';
import { debouncedReaction } from '@/utils/mobx';
import { reaction, toJS } from 'mobx';
@ -20,7 +20,7 @@ export default function reactions({ store, apolloClient }: ProcessContext) {
return;
}
const currentDate = getCurrentISODate();
const currentDate = getCurrentDateString();
const {
data: { evo_addproduct_types },
@ -77,7 +77,7 @@ export default function reactions({ store, apolloClient }: ProcessContext) {
reaction(
() => $calculation.$values.getValues(['leasingPeriod', 'leaseObjectType']),
async ({ leasingPeriod, leaseObjectType }) => {
const currentDate = getCurrentISODate();
const currentDate = getCurrentDateString();
const {
data: { evo_addproduct_types },
@ -161,7 +161,7 @@ export default function reactions({ store, apolloClient }: ProcessContext) {
leasingPeriod,
plPriceRub,
}) => {
const currentDate = getCurrentISODate();
const currentDate = getCurrentDateString();
const {
data: { evo_addproduct_types },
@ -274,7 +274,7 @@ export default function reactions({ store, apolloClient }: ProcessContext) {
leaseObjectType: leaseObjectTypeId,
engineType,
}) => {
const currentDate = getCurrentISODate();
const currentDate = getCurrentDateString();
const {
data: { evo_addproduct_types: trackerTypes },
} = await apolloClient.query({

View File

@ -1,7 +1,7 @@
import type { ValidationContext } from '../../types';
import type { ElementsTypes } from '@/Components/Calculation/config/map/values';
import * as CRMTypes from '@/graphql/crm.types';
import { getCurrentISODate } from '@/utils/date';
import { getCurrentDateString } from '@/utils/date';
export type ProductId = ElementsTypes['selectProduct'];
@ -27,7 +27,7 @@ export default function helper({ apolloClient, user }: ValidationContext) {
return null;
}
const currentDate = getCurrentISODate();
const currentDate = getCurrentDateString();
const {
data: { evo_coefficients },

View File

@ -3,7 +3,7 @@ import defaultValues from '@/config/default-values';
import * as CRMTypes from '@/graphql/crm.types';
import type { ProcessContext } from '@/process/types';
import type { CalculationValues } from '@/stores/calculation/values/types';
import { getCurrentISODate } from '@/utils/date';
import { getCurrentDateString } from '@/utils/date';
import dayjs from 'dayjs';
import { first, sort } from 'radash';
@ -80,7 +80,7 @@ export default function helper({ apolloClient }: Pick<ProcessContext, 'apolloCli
},
async getRates({ tarif: tarifId }: GetRatesInputValues) {
const currentDate = getCurrentISODate();
const currentDate = getCurrentDateString();
const {
data: { evo_rates },
@ -138,7 +138,7 @@ export default function helper({ apolloClient }: Pick<ProcessContext, 'apolloCli
floatingRate,
partialVAT,
}: GetTarifInputValues) {
const currentDate = getCurrentISODate();
const currentDate = getCurrentDateString();
const {
data: { evo_tarifs = [] },

View File

@ -4,7 +4,7 @@ import { crmTools } from '@/graphql/crm.tools';
import * as CRMTypes from '@/graphql/crm.types';
import { SEASON_TYPES } from '@/process/payments/lib/seasons-constants';
import type { ProcessContext } from '@/process/types';
import { getCurrentISODate } from '@/utils/date';
import { getCurrentDateString } from '@/utils/date';
import { normalizeOptions } from '@/utils/entity';
import { disposableReaction } from '@/utils/mobx';
import { reaction } from 'mobx';
@ -355,7 +355,7 @@ export default function reactions({ store, apolloClient, user }: ProcessContext)
reaction(
() => $calculation.element('selectQuote').getValue(),
async (quoteId) => {
const currentDate = getCurrentISODate();
const currentDate = getCurrentDateString();
let {
data: { evo_baseproducts },

View File

@ -6,7 +6,7 @@ import { STALE_TIME } from '@/constants/request';
import * as CRMTypes from '@/graphql/crm.types';
import type { ProcessContext } from '@/process/types';
import type { CalculationValues } from '@/stores/calculation/values/types';
import { getCurrentISODate } from '@/utils/date';
import { getCurrentDateString } from '@/utils/date';
import type { QueryFunctionContext } from '@tanstack/react-query';
import { flatten } from 'tools/object';
@ -38,7 +38,7 @@ export default function helper({
} = await apolloClient.query({
query: CRMTypes.GetAddproductTypesDocument,
variables: {
currentDate: getCurrentISODate(),
currentDate: getCurrentDateString(),
},
});

View File

@ -6,7 +6,7 @@ import { getTransTax } from '@/api/1c/query';
import { selectObjectCategoryTax } from '@/config/default-options';
import { STALE_TIME } from '@/constants/request';
import * as CRMTypes from '@/graphql/crm.types';
import { getCurrentISODate } from '@/utils/date';
import { getCurrentDateString } from '@/utils/date';
import { normalizeOptions } from '@/utils/entity';
import { disposableReaction } from '@/utils/mobx';
import dayjs from 'dayjs';
@ -250,7 +250,7 @@ export function common({ store, apolloClient, queryClient }: ProcessContext) {
data: { evo_addproduct_types },
} = await apolloClient.query({
query: CRMTypes.GetRegistrationTypesDocument,
variables: { currentDate: getCurrentISODate() },
variables: { currentDate: getCurrentDateString() },
});
const options = evo_addproduct_types?.filter((x) => {

View File

@ -4,7 +4,7 @@ import { STALE_TIME } from '@/constants/request';
import { crmTools } from '@/graphql/crm.tools';
import * as CRMTypes from '@/graphql/crm.types';
import { useStore } from '@/stores/hooks';
import { getCurrentISODate } from '@/utils/date';
import { getCurrentDateString } from '@/utils/date';
import { normalizeOptions } from '@/utils/entity';
import { useApolloClient } from '@apollo/client';
import { useQuery } from '@tanstack/react-query';
@ -16,7 +16,7 @@ import { useEffect } from 'react';
* @param {*} onCompleted
*/
function getMainData({ query }, onCompleted, user) {
const currentDate = getCurrentISODate();
const currentDate = getCurrentDateString();
query({
query: CRMTypes.GetLeadsDocument,

View File

@ -3,7 +3,7 @@
import { notification } from '@/Components/Common/Notification';
import * as CRMTypes from '@/graphql/crm.types';
import type { ProcessContext } from '@/process/types';
import { getCurrentISODate } from '@/utils/date';
import { getCurrentDateString } from '@/utils/date';
import { normalizeOptions } from '@/utils/entity';
import { reaction } from 'mobx';
import { uid } from 'radash';
@ -64,7 +64,7 @@ export function common({ store, apolloClient }: ProcessContext) {
firstPaymentPerc,
model: modelId,
}) => {
const currentDate = getCurrentISODate();
const currentDate = getCurrentDateString();
const {
data: { evo_addproduct_types },

View File

@ -1,7 +1,7 @@
import type { AgentsFields, AgentsRewardConditionsFields, AgentsSumFields } from './types';
import * as CRMTypes from '@/graphql/crm.types';
import type RootStore from '@/stores/root';
import { getCurrentISODate } from '@/utils/date';
import { getCurrentDateString } from '@/utils/date';
import { normalizeOptions } from '@/utils/entity';
import { disposableReaction } from '@/utils/mobx';
import type { ApolloClient } from '@apollo/client';
@ -41,7 +41,7 @@ export function fillAgentRewardReaction(
query: CRMTypes.GetRewardConditionsDocument,
variables: {
agentid,
currentDate: getCurrentISODate(),
currentDate: getCurrentDateString(),
},
});

View File

@ -4,7 +4,7 @@ import type { ValidationContext } from '../types';
import type { Elements } from '@/Components/Calculation/config/map/values';
import ValuesSchema from '@/config/schema/values';
import * as CRMTypes from '@/graphql/crm.types';
import { getCurrentISODate } from '@/utils/date';
import { getCurrentDateString } from '@/utils/date';
import { normalizeOptions } from '@/utils/entity';
import type { RefinementCtx } from 'zod';
import { z } from 'zod';
@ -29,7 +29,7 @@ function helper({ apolloClient, ctx }: ValidationContext & { ctx: RefinementCtx
query: CRMTypes.GetRewardConditionsDocument,
variables: {
agentid,
currentDate: getCurrentISODate(),
currentDate: getCurrentDateString(),
},
});

View File

@ -5,7 +5,7 @@ import { ESN, NSIB_MAX, VAT } from '@/constants/values';
import * as CRMTypes from '@/graphql/crm.types';
import helper from '@/process/calculate/lib/helper';
import { createCurrencyUtility } from '@/utils/currency';
import { getCurrentISODate } from '@/utils/date';
import { getCurrentDateString } from '@/utils/date';
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';
import { min, sum } from 'radash';
@ -127,7 +127,7 @@ export async function createRequestData({
await apolloClient.query({
query: CRMTypes.GetCoefficientsDocument,
variables: {
currentDate: getCurrentISODate(),
currentDate: getCurrentDateString(),
},
})
).data.evo_coefficients

View File

@ -1,4 +1,4 @@
import { getCurrentISODate } from './date';
import { getCurrentDateString } from './date';
import * as CRMTypes from '@/graphql/crm.types';
import type { ApolloClient } from '@apollo/client';
@ -33,7 +33,7 @@ export function createCurrencyUtility({ apolloClient }: Context) {
fetchPolicy: 'network-only',
query: CRMTypes.GetCurrencyChangesDocument,
variables: {
currentDate: getCurrentISODate(),
currentDate: getCurrentDateString(),
},
});

View File

@ -11,6 +11,10 @@ export function getCurrentISODate() {
return _currentDate().toISOString();
}
export function getCurrentDateString() {
return _currentDate().format('YYYY-MM-DD');
}
export function getCurrentDate() {
return _currentDate().toDate();
}