Skip to content

Commit

Permalink
Merge pull request #63 from Josmar-jr/fix/update-expiration-day
Browse files Browse the repository at this point in the history
fix: validate input value and updates correctly adminSetup
  • Loading branch information
ataideverton authored Sep 26, 2024
2 parents 8781d99 + ad08971 commit 2041f78
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed

- Fix validation and submit on lifespan settings for quotes

## [1.6.4] - 2024-09-05

Expand Down
32 changes: 24 additions & 8 deletions react/components/AppSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { FC } from 'react'
import React, { useState, useEffect } from 'react'
import { useQuery, useMutation } from 'react-apollo'
import { useIntl } from 'react-intl'
import type { NumberInputValue } from '@vtex/admin-ui'
import {
Page,
PageHeader,
Expand Down Expand Up @@ -31,6 +32,11 @@ const AppSettings: FC = () => {

const { data, loading } = useQuery(APP_SETTINGS, {
ssr: false,
onCompleted: (insideData) => {
if (insideData?.getAppSettings?.adminSetup) {
setSettingsState(insideData.getAppSettings.adminSetup)
}
},
})

const [saveSettings] = useMutation(SAVE_APP_SETTINGS)
Expand All @@ -49,18 +55,19 @@ const AppSettings: FC = () => {
input: settingsState,
},
})
.catch((err) => {
console.error(err)
.then(() => {
showToast({
message: formatMessage(adminMessages.saveSettingsFailure),
message: formatMessage(adminMessages.saveSettingsSuccess),
duration: 5000,
})
setSettingsLoading(false)
})
.then(() => {
.catch((err) => {
console.error(err)
showToast({
message: formatMessage(adminMessages.saveSettingsSuccess),
message: formatMessage(adminMessages.saveSettingsFailure),
duration: 5000,
tone: 'critical',
})
setSettingsLoading(false)
})
Expand All @@ -85,16 +92,25 @@ const AppSettings: FC = () => {
value={settingsState.cartLifeSpan}
label={formatMessage(adminMessages.cartLifeSpanLabel)}
min={1}
onChange={(event: any) =>
onBlur={() => {
if (settingsState.cartLifeSpan < 1) {
setSettingsState({
...settingsState,
cartLifeSpan: 1,
})
}
}}
onChange={(value: NumberInputValue) => {
setSettingsState({
...settingsState,
cartLifeSpan: event.value,
cartLifeSpan: Number(value),
})
}
}}
/>
</Box>
<Box as="section">
<Button
disabled={settingsState.cartLifeSpan < 1}
variant="primary"
onClick={() => handleSaveSettings()}
loading={settingsLoading}
Expand Down
6 changes: 1 addition & 5 deletions react/components/QuoteDetails/SaveButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ const SaveButtons = ({
updatingQuoteState
}
>
{isSalesRep ? (
<FormattedMessage id="store/b2b-quotes.quote-details.save" />
) : (
<FormattedMessage id="store/b2b-quotes.create.button.request-quote" />
)}
<FormattedMessage id="store/b2b-quotes.create.button.save-for-later" />
</Button>
</span>
</Fragment>
Expand Down

0 comments on commit 2041f78

Please sign in to comment.