u
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
* Upstream Triggers:
|
||||
* - `authAutomat`: Subscribes to auth state changes — calls `actions.load()` on
|
||||
* `'authed'` with a `selectedCompanyId`, and `actions.reset()` on `'anon'`.
|
||||
* - UI / Settings: Mutating actions (`upsert`, `remove`, `addImage`, `deleteImage`).
|
||||
* - UI / Settings: Mutating actions (`create`, `rename`, `remove`, `addImage`, `deleteImage`).
|
||||
*/
|
||||
|
||||
import { Automat } from 'react-automat';
|
||||
@@ -50,11 +50,11 @@ const actions = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Upsert a brand (create or update by name).
|
||||
* Create a brand (insert). 409 Brand already exists on duplicate name.
|
||||
* @param {{ name: string, gsprpinfo?: string }} body
|
||||
*/
|
||||
async upsert(body) {
|
||||
const res = await brandApi.upsert(body);
|
||||
async create(body) {
|
||||
const res = await brandApi.create(body);
|
||||
const row = res.brand;
|
||||
const brands = sortBrands([
|
||||
...brandAutomat.state.brands.filter((b) => b.id !== row.id),
|
||||
@@ -64,6 +64,21 @@ const actions = {
|
||||
return row;
|
||||
},
|
||||
|
||||
/**
|
||||
* Rename a brand. Returns `{ id, name, gsprpinfo, touchedArticleCount }`.
|
||||
* @param {number} id
|
||||
* @param {{ name?: string, gsprpinfo?: string }} body
|
||||
*/
|
||||
async rename(id, body) {
|
||||
const res = await brandApi.rename(id, body);
|
||||
const updated = res.brand ?? { id: res.id, name: res.name, gsprpinfo: res.gsprpinfo };
|
||||
const brands = sortBrands(
|
||||
brandAutomat.state.brands.map((b) => (b.id === id ? { ...b, ...updated } : b)),
|
||||
);
|
||||
brandAutomat.setState({ brands });
|
||||
return res;
|
||||
},
|
||||
|
||||
/**
|
||||
* Delete a brand by id.
|
||||
* @param {number} id
|
||||
|
||||
Reference in New Issue
Block a user