Phoenix Documentation
Phoenix ProductionPhoenix PreviewContentful
Primary version
Primary version
  • 🔥Phoenix 🔥
  • Installation + Usage
    • Prerequisites
    • Installation
    • Usage
  • Development
    • Architecture
      • Heroku
    • Content Types
      • Action Stats Block
      • Campaign
      • Content Block
      • Cause Page
      • Company Page
      • Current Club Block
      • Current School Block
      • Embed
      • External Link
      • Landing Page
      • Link Action
      • Metadata
      • Page
      • Photo Submission Action
      • Selection Submission Action
      • Share Action
      • Signup Referrals Block
      • Social Drive Action
      • Voter Registration Action
      • Voter Registration Drive Action
      • Voter Registration Marketing Page
      • Voter Registration Referrals Block
    • Features
      • Affiliate Opt In
      • Affiliate Scholarship Block
      • Analytics Waypoint
      • Delayed Element
      • Dismissable Element
      • Stat Card
      • General Buttons
      • Groups
      • Paginated Campaign Gallery
      • Popover Dispatcher
      • Refer A Friend
      • Referrals Gallery
      • Sitewide Banner
      • Sixpack A/B Testing
        • Code Tests
        • Contentful Tests
        • Testing Tips
      • Tooltip
      • Traffic Distribution
      • Volunteer Credits
      • Voter Registration
      • Zendesk Form
    • Contentful
      • Workflow
      • Content Management API Scripts
    • Helpers
  • Phoenix API
    • v2
      • Campaigns Resource
      • Posts Resource
      • Zendesk Endpoint
  • Data + Performance
    • Monitoring
    • Analytics
    • Logging
  • Contributing Instructions
    • Edit This Documentation
    • Glossary
Powered by GitBook
On this page
  • JS Helper Methods
  • Using/Creating Helper Methods
  • Clean up
  • Tests (I don't Jest)
  1. Development

Helpers

PreviousContent Management API ScriptsNextv2

Last updated 5 years ago

We have two suites of helper methods in the Phoenix codebase.

  1. PHP helper methods globally available on the backend PHP application in

  2. JS helper methods which can be imported from anywhere in our front-end React application in the directory

JS Helper Methods

We organize our helpers in filenames with logical categories. E.g. methods related to user & authentication information in helpers/auth.

We also have a large amount of miscellaneous or otherwise uncategorized methods within the main helpers/index.js file.

Using/Creating Helper Methods

When building a piece of repeatable contained logic (e.g. to generate a user friendly representation of a Contentful Date), our rule of thumb is to first peruse our suite of helpers to see if this functionality already exists as a method (or if our logic can at least utilize an existing helper). Otherwise, if a new helper method is necessary (such as when this logic has already been applied elsewhere and can be abstracted), add the new helper method to the appropriate categorized file, or create a new category file (helpers/[new-category].js).

Clean up

Many helper methods remain uncategorized in the main helpers/index.js file, if using an existing helper that looks like it can fit in an existing category -- feel free to move it in! If you notice a new logical grouping forming or already existing -- feel free to port them over to the new categorized file!

Tests (I don't )

We're missing tests on many of our existing helper functions. If utilizing an existing helper method - or certainly if adding a new one - we recommend creating an accompanying set of tests. This would either go in the main helpers/test.js file for methods in the main helpers/index.js file, or in a helpers/[category-name].test.js file. (If one doesn't already exist, please feel free to backfill!)

app/helpers.php
resources/assets/helpers
a method
Jest