u
This commit is contained in:
@@ -56,6 +56,14 @@ export default class CompanySettingsDialog extends Component {
|
||||
this.loadTerminals = this.loadTerminals.bind(this);
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
if (this.props.open) {
|
||||
this.setState({ error: null });
|
||||
void this.loadCompany();
|
||||
void this.loadTerminals();
|
||||
}
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps) {
|
||||
const { open } = this.props;
|
||||
if (open && !prevProps.open) {
|
||||
@@ -78,9 +86,9 @@ export default class CompanySettingsDialog extends Component {
|
||||
try {
|
||||
const session = await this.context.authMePromise;
|
||||
const companyId = requireDefined(session.user?.selectedCompanyId, 'selectedCompanyId');
|
||||
const companies = await this.context.companyPromise;
|
||||
const companyData = await this.context.companyPromise;
|
||||
const companyRow = requireDefined(
|
||||
companies.find((c) => c.id === companyId),
|
||||
Array.isArray(companyData) ? companyData.find((c) => c.id === companyId) : companyData,
|
||||
'company',
|
||||
);
|
||||
this.syncFormFromCompany(companyRow);
|
||||
@@ -92,7 +100,7 @@ export default class CompanySettingsDialog extends Component {
|
||||
async loadTerminals() {
|
||||
try {
|
||||
const terminals = await this.context.posterminalPromise;
|
||||
this.setState({ terminals });
|
||||
this.setState({ terminals: Array.isArray(terminals) ? terminals : [] });
|
||||
} catch (err) {
|
||||
notifyError(err);
|
||||
}
|
||||
@@ -115,7 +123,7 @@ export default class CompanySettingsDialog extends Component {
|
||||
}
|
||||
|
||||
const terminals = await this.context.updatePosterminal();
|
||||
this.setState({ newTerminalName: '', terminals });
|
||||
this.setState({ newTerminalName: '', terminals: Array.isArray(terminals) ? terminals : [] });
|
||||
} catch (err) {
|
||||
notifyError(err);
|
||||
} finally {
|
||||
@@ -127,7 +135,7 @@ export default class CompanySettingsDialog extends Component {
|
||||
try {
|
||||
await this.context.posterminal.delete(terminal.id);
|
||||
const terminals = await this.context.updatePosterminal();
|
||||
this.setState({ terminals });
|
||||
this.setState({ terminals: Array.isArray(terminals) ? terminals : [] });
|
||||
} catch (err) {
|
||||
notifyError(err);
|
||||
}
|
||||
@@ -266,7 +274,7 @@ export default class CompanySettingsDialog extends Component {
|
||||
|
||||
<Box>
|
||||
<List dense sx={{ py: 0 }}>
|
||||
{this.state.terminals.map((terminal) => (
|
||||
{(this.state.terminals || []).map((terminal) => (
|
||||
<ListItem
|
||||
key={terminal.id}
|
||||
sx={{ px: 0, py: 0.5 }}
|
||||
|
||||
Reference in New Issue
Block a user