-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UIORGS-336 Create or change vendor code using number generator (#536)
Refs UXPROD-3891, UIORGS-336, UIORGS-337
- Loading branch information
1 parent
e94bc6f
commit e02c827
Showing
19 changed files
with
647 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 47 additions & 10 deletions
57
src/Organizations/OrganizationForm/OrganizationSummaryForm/FieldCode/FieldCode.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/Settings/NumberGeneratorSettings/NumberGeneratorSettings.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { FormattedMessage } from 'react-intl'; | ||
|
||
import { Loading } from '@folio/stripes/components'; | ||
import { useOkapiKy } from '@folio/stripes/core'; | ||
import { useShowCallout } from '@folio/stripes-acq-components'; | ||
|
||
import NumberGeneratorSettingsForm from './NumberGeneratorSettingsForm'; | ||
import { SETTINGS_API } from '../../common/constants/api'; | ||
import { VENDOR_CODE_GENERATOR_SETTINGS_KEY } from '../../common/constants/numberGenerator'; | ||
import { useVendorCodeGeneratorSettings } from '../../common/hooks/useVendorCodeGeneratorSettings'; | ||
|
||
const NumberGeneratorSettings = () => { | ||
const { vendorCodeSetting, isLoading } = useVendorCodeGeneratorSettings(); | ||
const ky = useOkapiKy(); | ||
const sendCallout = useShowCallout(); | ||
|
||
const onSubmit = async ({ [VENDOR_CODE_GENERATOR_SETTINGS_KEY]: value }) => { | ||
try { | ||
if (vendorCodeSetting) { | ||
await ky.put(`${SETTINGS_API}/${vendorCodeSetting.id}`, { | ||
json: { ...vendorCodeSetting, value }, | ||
}); | ||
} else { | ||
await ky.post(SETTINGS_API, { | ||
json: { key: VENDOR_CODE_GENERATOR_SETTINGS_KEY, value }, | ||
}); | ||
} | ||
|
||
sendCallout({ | ||
message: <FormattedMessage id="ui-organizations.settings.numberGeneratorOptions.save.success" />, | ||
}); | ||
} catch (error) { | ||
sendCallout({ | ||
type: 'error', | ||
message: <FormattedMessage id="ui-organizations.settings.numberGeneratorOptions.save.error" />, | ||
}); | ||
} | ||
}; | ||
|
||
if (isLoading) { | ||
return <Loading />; | ||
} | ||
|
||
return ( | ||
<NumberGeneratorSettingsForm | ||
initialValues={{ [VENDOR_CODE_GENERATOR_SETTINGS_KEY]: vendorCodeSetting?.value }} | ||
onSubmit={onSubmit} | ||
/> | ||
); | ||
}; | ||
|
||
export default NumberGeneratorSettings; |
Oops, something went wrong.