Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Allow processing fee field to be manually edited #291

Merged
merged 1 commit into from
Apr 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion components/admin/requests/payment-information/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ const Card: FC<Props> = props => {
paymentInformation={{
paymentMethod,
donationAmount,
processingFee,
shippingAddressSameAsHomeAddress,
shippingFullName,
shippingAddressLine1,
Expand Down Expand Up @@ -135,7 +136,7 @@ const Card: FC<Props> = props => {
<SimpleGrid columns={2} spacingX="70px" spacingY="12px">
<Box>
<Text as="p" textStyle="body-regular" textAlign="left">
Permit Fee (fixed)
Permit Fee
</Text>
</Box>
<Box>
Expand Down
31 changes: 2 additions & 29 deletions components/admin/requests/payment-information/Form.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
import { PaymentInformationFormData } from '@tools/admin/requests/payment-information';
import {
FormControl,
FormLabel,
Input,
Text,
Stack,
FormHelperText,
Radio,
Box,
InputGroup,
InputLeftElement,
Grid,
GridItem,
Divider,
} from '@chakra-ui/react'; // Chakra UI
import { Text, Stack, FormHelperText, Radio, Box, Grid, GridItem, Divider } from '@chakra-ui/react'; // Chakra UI
import { PaymentType } from '@lib/graphql/types';
import TextField from '@components/form/TextField';
import RadioGroupField from '@components/form/RadioGroupField';
Expand Down Expand Up @@ -52,20 +38,7 @@ export default function PaymentDetailsForm({ paymentInformation }: PaymentDetail
</GridItem>

<GridItem>
<FormControl isRequired isDisabled>
<FormLabel>
{'Permit fee '}
<Box as="span" textStyle="body-regular">
{'(fixed cost)'}
</Box>
</FormLabel>
<InputGroup>
<InputLeftElement pointerEvents="none" color="texticon.filler" fontSize="1.2em">
{'$'}
</InputLeftElement>
<Input placeholder="26" />
</InputGroup>
</FormControl>
<TextField name="paymentInformation.processingFee" label="Permit fee" monetaryInput />
</GridItem>

<GridItem colSpan={1}>
Expand Down
11 changes: 8 additions & 3 deletions lib/applications/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ export const createNewApplication: Resolver<

const paymentInformation = {
paymentMethod: input.paymentMethod,
processingFee: input.processingFee,
donationAmount,
shippingAddressSameAsHomeAddress: input.shippingAddressSameAsHomeAddress,
shippingFullName: input.shippingFullName,
Expand Down Expand Up @@ -382,7 +383,6 @@ export const createNewApplication: Resolver<
application = await prisma.application.create({
data: {
type: 'NEW',
processingFee: process.env.PROCESSING_FEE,
donationAmount: donationAmount || 0,
// Connect to applicant if applicant exists in DB
...(applicantId && {
Expand Down Expand Up @@ -557,8 +557,11 @@ export const createRenewalApplication: Resolver<
otherRequiresWiderParkingSpaceReason,
};

const { processingFee } = input;

const paymentInformation = {
paymentMethod,
processingFee,
donationAmount,
shippingAddressSameAsHomeAddress,
shippingFullName,
Expand Down Expand Up @@ -606,7 +609,6 @@ export const createRenewalApplication: Resolver<
createdRenewalApplication = await prisma.application.create({
data: {
type: 'RENEWAL',
processingFee: process.env.PROCESSING_FEE,
donationAmount: donationAmount || 0,
phone: stripPhoneNumber(phone),
...data,
Expand Down Expand Up @@ -965,8 +967,12 @@ export const createReplacementApplication: Resolver<
city,
postalCode,
};

const { processingFee } = input;

const paymentInformation = {
paymentMethod,
processingFee,
donationAmount,
shippingAddressSameAsHomeAddress,
shippingFullName,
Expand Down Expand Up @@ -1034,7 +1040,6 @@ export const createReplacementApplication: Resolver<
application = await prisma.application.create({
data: {
type: 'REPLACEMENT',
processingFee: process.env.PROCESSING_FEE,
donationAmount: donationAmount || 0,
phone: stripPhoneNumber(phone),
postalCode: stripPostalCode(postalCode),
Expand Down
9 changes: 6 additions & 3 deletions lib/applications/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,9 @@ export default gql`
requiresWiderParkingSpaceReason: RequiresWiderParkingSpaceReason
otherRequiresWiderParkingSpaceReason: String

# Payment information (omit processing fee)
# Payment information
paymentMethod: PaymentType!
processingFee: String! # Input monetary value as string
donationAmount: String # Input monetary value as string
# Shipping information
shippingAddressSameAsHomeAddress: Boolean!
Expand Down Expand Up @@ -454,6 +455,7 @@ export default gql`

# Payment information
paymentMethod: PaymentType!
processingFee: String # Input monetary value as string
donationAmount: String # Input monetary value as string
# Shipping information
shippingAddressSameAsHomeAddress: Boolean!
Expand Down Expand Up @@ -555,9 +557,9 @@ export default gql`
stolenPoliceOfficerName: String
eventDescription: String

# Payment information (omit processing fee)
paymentMethod: PaymentType!
# Input monetary value as string
processingFee: String!
donationAmount: String

# Shipping information
Expand Down Expand Up @@ -722,8 +724,9 @@ export default gql`
# Application ID
id: Int!

# Payment information (omit processing fee)
# Payment information
paymentMethod: PaymentType!
processingFee: String!
donationAmount: String

# Shipping information
Expand Down
7 changes: 5 additions & 2 deletions lib/applications/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
AccessibleConvertedVanLoadingMethod,
RequiresWiderParkingSpaceReason,
} from '@lib/graphql/types';
import { phoneNumberRegex, postalCodeRegex } from '@lib/utils/validation';
import { monetaryValueRegex, phoneNumberRegex, postalCodeRegex } from '@lib/utils/validation';

/**
* Additional Questions form validation schema
Expand Down Expand Up @@ -75,9 +75,12 @@ export const paymentInformationSchema = object({
.oneOf(Object.values(PaymentType))
.required('Please select a payment method'),
donationAmount: string()
.matches(/^([0-9]+\.?[0-9]{0,2}|\.[0-9]{1,2}|)$/, 'Please enter a valid amount')
.matches(monetaryValueRegex, 'Please enter a valid amount')
.nullable()
.default(null),
processingFee: string()
.matches(monetaryValueRegex, 'Please enter a valid amount')
.required('Please enter a permit fee'),
shippingAddressSameAsHomeAddress: bool().default(false),
shippingFullName: string()
.nullable()
Expand Down
4 changes: 4 additions & 0 deletions lib/graphql/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ export type CreateNewApplicationInput = {
requiresWiderParkingSpaceReason: Maybe<RequiresWiderParkingSpaceReason>;
otherRequiresWiderParkingSpaceReason: Maybe<Scalars['String']>;
paymentMethod: PaymentType;
processingFee: Scalars['String'];
donationAmount: Maybe<Scalars['String']>;
shippingAddressSameAsHomeAddress: Scalars['Boolean'];
shippingFullName: Maybe<Scalars['String']>;
Expand Down Expand Up @@ -373,6 +374,7 @@ export type CreateRenewalApplicationInput = {
requiresWiderParkingSpaceReason: Maybe<RequiresWiderParkingSpaceReason>;
otherRequiresWiderParkingSpaceReason: Maybe<Scalars['String']>;
paymentMethod: PaymentType;
processingFee: Scalars['String'];
donationAmount: Maybe<Scalars['String']>;
shippingAddressSameAsHomeAddress: Scalars['Boolean'];
shippingFullName: Maybe<Scalars['String']>;
Expand Down Expand Up @@ -418,6 +420,7 @@ export type CreateReplacementApplicationInput = {
stolenPoliceOfficerName: Maybe<Scalars['String']>;
eventDescription: Maybe<Scalars['String']>;
paymentMethod: PaymentType;
processingFee: Scalars['String'];
donationAmount: Maybe<Scalars['String']>;
shippingAddressSameAsHomeAddress: Scalars['Boolean'];
shippingFullName: Maybe<Scalars['String']>;
Expand Down Expand Up @@ -1317,6 +1320,7 @@ export type UpdateApplicationGuardianInformationResult = {
export type UpdateApplicationPaymentInformationInput = {
id: Scalars['Int'];
paymentMethod: PaymentType;
processingFee: Scalars['String'];
donationAmount: Maybe<Scalars['String']>;
shippingAddressSameAsHomeAddress: Scalars['Boolean'];
shippingFullName: Maybe<Scalars['String']>;
Expand Down
5 changes: 5 additions & 0 deletions lib/utils/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ export const postalCodeRegex = /(^(?!.*[DFIOQU])[A-VXY][0-9][A-Z] ?[0-9][A-Z][0-
* Regex to match phone numbers in the form '123-456-7890' and '1234567890'
*/
export const phoneNumberRegex = /(^(\d{3}-?\d{3}-?\d{4}$))/;

/**
* Regex to match monetary values
*/
export const monetaryValueRegex = /^([0-9]+\.?[0-9]{0,2}|\.[0-9]{1,2}|)$/;
1 change: 1 addition & 0 deletions tools/admin/requests/create-new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ export const INITIAL_ADDITIONAL_QUESTIONS: AdditionalInformationFormData = {
// Initial data for payment details in application forms
export const INITIAL_PAYMENT_DETAILS: PaymentInformationFormData = {
paymentMethod: null,
processingFee: '26',
sherryhli marked this conversation as resolved.
Show resolved Hide resolved
donationAmount: '',
shippingAddressSameAsHomeAddress: false,
shippingFullName: '',
Expand Down
1 change: 1 addition & 0 deletions tools/admin/requests/payment-information.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
export type PaymentInformationFormData = Pick<
Application,
| 'donationAmount'
| 'processingFee'
| 'shippingAddressSameAsHomeAddress'
| 'shippingFullName'
| 'shippingAddressLine1'
Expand Down