path params vs state are out of sync on OrderPage and SalePage

This commit is contained in:
Vesa Luusua 2017-05-05 17:07:24 +03:00
parent 3d1707d1f6
commit 809ebdb4ab
4 changed files with 14 additions and 6 deletions

View file

@ -13,7 +13,7 @@ import css from './OrderPage.css';
// OrderPage handles data loading
// It show loading data text or OrderDetailsPanel (and later also another panel for messages).
export const OrderPageComponent = props => {
const { currentUser, fetchOrderError, intl, transaction } = props;
const { currentUser, fetchOrderError, intl, params, transaction } = props;
const currentTransaction = ensureTransaction(transaction);
const currentListing = ensureListing(currentTransaction.listing);
const title = currentListing.attributes.title;
@ -21,6 +21,7 @@ export const OrderPageComponent = props => {
// Redirect users with someone else's direct link to their own inbox/orders page.
const isDataAvailable = currentUser &&
currentTransaction.id &&
currentTransaction.id.uuid === params.id &&
currentTransaction.customer &&
!fetchOrderError;
const isOwnSale = isDataAvailable && currentUser.id.uuid === currentTransaction.customer.id.uuid;
@ -60,12 +61,13 @@ export const OrderPageComponent = props => {
OrderPageComponent.defaultProps = { transaction: null, currentUser: null, fetchOrderError: null };
const { instanceOf, oneOf } = PropTypes;
const { instanceOf, oneOf, shape, string } = PropTypes;
OrderPageComponent.propTypes = {
currentUser: propTypes.currentUser,
fetchOrderError: instanceOf(Error),
intl: intlShape.isRequired,
params: shape({ id: string }).isRequired,
tab: oneOf(['details', 'discussion']).isRequired,
transaction: propTypes.transaction,
};

View file

@ -12,8 +12,9 @@ import { OrderPageComponent } from './OrderPage';
describe('OrderPage', () => {
it('matches snapshot', () => {
const txId = 'tx-order-1';
const transaction = createTransaction({
id: 'tx-order-1',
id: txId,
state: 'state/preauthorized',
booking: createBooking(
'booking1',
@ -27,6 +28,7 @@ describe('OrderPage', () => {
const props = {
currentUser: createCurrentUser('customer1'),
params: { id: txId },
transaction,
tab: 'details',
intl: fakeIntl,

View file

@ -14,7 +14,7 @@ import css from './SalePage.css';
// SalePage handles data loading
// It show loading data text or SaleDetailsPanel (and later also another panel for messages).
export const SalePageComponent = props => {
const { currentUser, fetchSaleError, intl, onAcceptSale, onRejectSale, transaction } = props;
const { currentUser, fetchSaleError, intl, onAcceptSale, onRejectSale, params, transaction } = props;
const currentTransaction = ensureTransaction(transaction);
const currentListing = ensureListing(currentTransaction.listing);
const title = currentListing.attributes.title;
@ -22,6 +22,7 @@ export const SalePageComponent = props => {
// Redirect users with someone else's direct link to their own inbox/sales page.
const isDataAvailable = currentUser &&
currentTransaction.id &&
currentTransaction.id.uuid === params.id &&
currentTransaction.provider &&
!fetchSaleError;
const isOwnSale = isDataAvailable && currentUser.id.uuid === currentTransaction.provider.id.uuid;
@ -76,7 +77,7 @@ export const SalePageComponent = props => {
SalePageComponent.defaultProps = { transaction: null, currentUser: null, fetchSaleError: null };
const { func, instanceOf, oneOf } = PropTypes;
const { func, instanceOf, oneOf, shape, string } = PropTypes;
SalePageComponent.propTypes = {
currentUser: propTypes.currentUser,
@ -84,6 +85,7 @@ SalePageComponent.propTypes = {
intl: intlShape.isRequired,
onAcceptSale: func.isRequired,
onRejectSale: func.isRequired,
params: shape({ id: string }).isRequired,
tab: oneOf(['details', 'discussion']).isRequired,
transaction: propTypes.transaction,
};

View file

@ -12,8 +12,9 @@ import { SalePageComponent } from './SalePage';
describe('SalePage', () => {
it('matches snapshot', () => {
const txId = 'tx-sale-1';
const transaction = createTransaction({
id: 'tx-sale-1',
id: txId,
state: 'state/preauthorized',
booking: createBooking(
'booking1',
@ -29,6 +30,7 @@ describe('SalePage', () => {
currentUser: createCurrentUser('provider1'),
onAcceptSale: () => {},
onRejectSale: () => {},
params: { id: txId },
transaction,
tab: 'details',
intl: fakeIntl,