Skip to content

Commit

Permalink
debt: Remove unused tiers from mutations
Browse files Browse the repository at this point in the history
  • Loading branch information
Betree committed Aug 23, 2024
1 parent 65c101c commit c547f9c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 21 deletions.
18 changes: 1 addition & 17 deletions components/edit-collective/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import { getApplicableTaxesForCountry, TaxType } from '@opencollective/taxes';
import { InfoCircle } from '@styled-icons/boxicons-regular/InfoCircle';
import { ArrowBack } from '@styled-icons/material/ArrowBack';
import dayjs from 'dayjs';
import { cloneDeep, find, get, isNil, set } from 'lodash';
import { cloneDeep, get, isNil, set } from 'lodash';
import { withRouter } from 'next/router';
import { defineMessages, FormattedMessage, injectIntl } from 'react-intl';

import { AccountTypesWithHost, CollectiveType, defaultBackgroundImage } from '../../lib/constants/collectives';
import { Currency } from '../../lib/constants/currency';
import { TierTypes } from '../../lib/constants/tiers-types';
import { VAT_OPTIONS } from '../../lib/constants/vat';
import { convertDateFromApiUtc, convertDateToApiUtc } from '../../lib/date-utils';
import { isValidUrl } from '../../lib/utils';
Expand Down Expand Up @@ -282,15 +281,9 @@ class EditCollectiveForm extends React.Component {
collective.slug = collective.slug ? collective.slug.replace(/.*\//, '') : '';
collective.tos = get(collective, 'settings.tos');

// TODO Remove this once tier legacy is removed
const tiers = collective.tiers && collective.tiers.filter(tier => tier.type !== TierTypes.TICKET);
const tickets = collective.tiers && collective.tiers.filter(tier => tier.type === TierTypes.TICKET);

return {
modified: false,
collective,
tiers: tiers.length === 0 ? [] : tiers,
tickets: tickets.length === 0 ? [] : tickets,
validStartDate: true,
validEndDate: true,
isValidSocialLinks: true,
Expand Down Expand Up @@ -352,15 +345,6 @@ class EditCollectiveForm extends React.Component {
async handleSubmit() {
const collective = { ...this.state.collective };

// Add Tiers and Tickets
collective.tiers = [];
if (find(this.state.tiers, 'name')) {
collective.tiers = [...this.state.tiers];
}
if (find(this.state.tickets, 'name')) {
collective.tiers = [...collective.tiers, ...this.state.tickets];
}

// Add a confirm if slug changed
if (collective.slug !== this.props.collective.slug) {
if (
Expand Down
1 change: 1 addition & 0 deletions components/tier-page/graphql/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const tierPageQuery = gqlV1/* GraphQL */ `
query TierPage($tierId: Int!) {
Tier(id: $tierId) {
id
idV2

Check failure on line 9 in components/tier-page/graphql/queries.js

View workflow job for this annotation

GitHub Actions / lint

Cannot query field "idV2" on type "Tier". Did you mean "id"?
name
slug
description
Expand Down
14 changes: 11 additions & 3 deletions components/tier-page/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React, { Component } from 'react';

Check failure on line 1 in components/tier-page/index.js

View workflow job for this annotation

GitHub Actions / lint

Run autofix to sort these imports!
import PropTypes from 'prop-types';
import { gql } from '@apollo/client';
import { themeGet } from '@styled-system/theme-get';
import { withRouter } from 'next/router';
import { FormattedMessage } from 'react-intl';
import styled from 'styled-components';

// Open Collective Frontend imports
import INTERVALS from '../../lib/constants/intervals';
import { gqlV1 } from '../../lib/graphql/helpers';
import { isTierExpired } from '../../lib/tier-utils';
import { getCollectivePageRoute } from '../../lib/url-helpers';
import { getWebsiteUrl } from '../../lib/utils';
Expand All @@ -32,6 +32,7 @@ import TierLongDescription from './TierLongDescription';
import TierVideo from './TierVideo';

import BubblesSVG from './Bubbles.svg';
import { API_V2_CONTEXT } from '../../lib/graphql/helpers';

const generateBackground = (theme, image) => {
const color = theme.colors.primary[300];
Expand Down Expand Up @@ -80,8 +81,14 @@ const ProgressInfoContainer = styled.div`
`;

/** A mutation with all the info that user is allowed to edit on this page */
const editTierMutation = gqlV1/* GraphQL */ `
mutation UpdateTier($id: Int!, $name: String, $description: String, $longDescription: String, $videoUrl: String) {
const editTierMutation = gql`
mutation EditTierPage(
$id: String!
$name: String
$description: String
$longDescription: String
$videoUrl: String
) {
editTier(
tier: { id: $id, description: $description, name: $name, longDescription: $longDescription, videoUrl: $videoUrl }
) {
Expand Down Expand Up @@ -206,6 +213,7 @@ class TierPage extends Component {
<H1 fontSize="40px" textAlign="left" color="black.900" wordBreak="break-word" mb={3} data-cy="TierName">
<InlineEditField
mutation={editTierMutation}
mutationOptions={{ context: API_V2_CONTEXT }}
canEdit={canEdit}
values={tier}
field="name"
Expand Down
2 changes: 1 addition & 1 deletion test/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ Cypress.Commands.add('createCollective', ({ type = 'ORGANIZATION', email = defau
}
}
`,
variables: { collective: { location: {}, name: 'TestOrg', slug: '', tiers: [], type, ...params } },
variables: { collective: { location: {}, name: 'TestOrg', slug: '', type, ...params } },
}).then(({ body }) => {
return body.data.createCollective;
});
Expand Down

0 comments on commit c547f9c

Please sign in to comment.