diff --git a/app/assets/stylesheets/classified_listings.scss b/app/assets/stylesheets/classified_listings.scss index 9d6bf55ac..b0a8a9bb8 100644 --- a/app/assets/stylesheets/classified_listings.scss +++ b/app/assets/stylesheets/classified_listings.scss @@ -6,6 +6,9 @@ text-align: left; max-width: 100%; min-height: 100vh; + &.classifieds-form-container { + margin: 90px auto 150px; + } @media screen and (min-width: 950px) { margin: 40px auto; } @@ -143,7 +146,7 @@ ); @media screen and (min-width: 580px) { border-radius: 8px; - margin: 100px auto 20px; + margin: 20px auto 20px; } * { box-sizing: border-box; @@ -268,6 +271,10 @@ theme-container-box-shadow, 2px 2px 8px darken($light-medium-gray, 5%) ); + &.cta-draft { + color: $black; + background: $yellow; + } } .listings-current-credits { position: fixed; @@ -611,7 +618,9 @@ form.listings-contact-via-connect { margin-right: 5px; display: inline-block; width: fit-content; + cursor: pointer; margin-bottom: 10px; + user-select: none; @include themeable( color, theme-color, @@ -740,9 +749,15 @@ form.listings-contact-via-connect { border-radius: 3px; position: relative; background: var(--theme-container-background, #fff); + + &.draft { + background: var(--theme-container-accent-background, #fffeec) + } + &.expired { opacity: 0.7; } + .listing-org { @include themeable( background, @@ -824,6 +839,11 @@ form.listings-contact-via-connect { background: $green; color: $black; } + + &.yellow { + background: $yellow; + color: $black; + } &.red { background: $red; diff --git a/app/assets/stylesheets/dashboard.scss b/app/assets/stylesheets/dashboard.scss index 79f4b5de7..70fcfcd64 100644 --- a/app/assets/stylesheets/dashboard.scss +++ b/app/assets/stylesheets/dashboard.scss @@ -143,7 +143,7 @@ justify-content: space-between; align-items: center; - @media screen and (max-width: 426px) { + @media screen and (max-width: 600px) { flex-direction: column; align-items: stretch; } @@ -152,7 +152,7 @@ display: inline-block; padding: 14px; - @media screen and (max-width: 426px) { + @media screen and (max-width: 600px) { margin-bottom: 15px; text-align: center; } diff --git a/app/assets/stylesheets/delete-confirm.scss b/app/assets/stylesheets/delete-confirm.scss deleted file mode 100644 index 631592ad9..000000000 --- a/app/assets/stylesheets/delete-confirm.scss +++ /dev/null @@ -1,26 +0,0 @@ -@import 'variables'; - -.delete-confirm{ - padding:150px 10px; - min-height:300px; - h4{ - background:$black; - padding:5px 8px; - color:white; - display:inline-block; - margin-bottom:0px; - } - h2{ - font-size:22px; - margin-bottom:40px; - } - a.delete-link{ - background:$red; - color:white; - padding:10px 15px; - &:hover{ - color:white; - opacity:0.9; - } - } -} \ No newline at end of file diff --git a/app/assets/stylesheets/minimal.scss b/app/assets/stylesheets/minimal.scss index e9ce11c01..af46b11f3 100644 --- a/app/assets/stylesheets/minimal.scss +++ b/app/assets/stylesheets/minimal.scss @@ -20,7 +20,6 @@ @import 'signup-modal'; @import 'tags'; @import 'live'; -@import 'delete-confirm'; @import 'preact/sidebar-widget'; @import 'preact/article-form'; @import 'tag-edit'; diff --git a/app/assets/stylesheets/scaffolds.scss b/app/assets/stylesheets/scaffolds.scss index 3f63dbee8..92a99bebb 100644 --- a/app/assets/stylesheets/scaffolds.scss +++ b/app/assets/stylesheets/scaffolds.scss @@ -221,3 +221,28 @@ body.comic-sans-article-body { body.pro-status-true .pro-visible-block { display: block !important;; } + +.delete-confirm{ + padding:150px 10px; + min-height:300px; + h4{ + background:$black; + padding:5px 8px; + color:white; + display:inline-block; + margin-bottom:0px; + } + h2{ + font-size:22px; + margin-bottom:40px; + } + a.delete-link{ + background:$red; + color:white; + padding:10px 15px; + &:hover{ + color:white; + opacity:0.9; + } + } +} \ No newline at end of file diff --git a/app/controllers/classified_listings_controller.rb b/app/controllers/classified_listings_controller.rb index 547e6d7da..64bfe3357 100644 --- a/app/controllers/classified_listings_controller.rb +++ b/app/controllers/classified_listings_controller.rb @@ -1,6 +1,6 @@ class ClassifiedListingsController < ApplicationController include ClassifiedListingsToolkit - before_action :set_classified_listing, only: %i[edit update] + before_action :set_classified_listing, only: %i[edit update destroy] before_action :set_cache_control_headers, only: %i[index] before_action :raise_banned, only: %i[new create update] after_action :verify_authorized, only: %i[edit update] @@ -45,9 +45,21 @@ class ClassifiedListingsController < ApplicationController @classified_listing.user_id = current_user.id cost = ClassifiedListing.cost_by_category(@classified_listing.category) - org = Organization.find_by(id: @classified_listing.organization_id) + if listing_params[:action] == "draft" + @classified_listing.published = false + if @classified_listing.save + redirect_to "/listings/dashboard" + else + @credits = current_user.credits.unspent + @classified_listing.cached_tag_list = listing_params[:tag_list] + @organizations = current_user.organizations + render :new + end + return + end + available_org_credits = org.credits.unspent if org available_user_credits = current_user.credits.unspent @@ -64,27 +76,23 @@ class ClassifiedListingsController < ApplicationController def update authorize @classified_listing + cost = ClassifiedListing.cost_by_category(@classified_listing.category) + # NOTE: this should probably be split in three different actions: bump, unpublish, publish - if listing_params[:action] == "bump" - cost = ClassifiedListing.cost_by_category(@classified_listing.category) + return bump_listing(cost) if listing_params[:action] == "bump" - org = Organization.find_by(id: @classified_listing.organization_id) - - available_org_credits = org.credits.unspent if org - available_user_credits = current_user.credits.unspent - - if org && available_org_credits.size >= cost - charge_credits_before_bump(org, cost) - elsif available_user_credits.size >= cost - charge_credits_before_bump(current_user, cost) - else - redirect_to(credits_path, notice: "Not enough available credits") && return - end - elsif listing_params[:action] == "unpublish" + if listing_params[:action] == "unpublish" unpublish_listing + redirect_to "/listings/dashboard" + return elsif listing_params[:action] == "publish" + unless @classified_listing.bumped_at? + first_publish(cost) + return + end + publish_listing - elsif listing_params[:body_markdown].present? && @classified_listing.bumped_at > 24.hours.ago + elsif listing_params[:body_markdown].present? && ((@classified_listing.bumped_at && @classified_listing.bumped_at > 24.hours.ago) || !@classified_listing.published) update_listing_details end @@ -104,6 +112,17 @@ class ClassifiedListingsController < ApplicationController @user_credits = current_user.unspent_credits_count end + def delete_confirm + @classified_listing = ClassifiedListing.find_by(slug: params[:slug]) + authorize @classified_listing + end + + def destroy + authorize @classified_listing + @classified_listing.destroy! + redirect_to "/listings/dashboard", notice: "Listing was successfully deleted." + end + private def create_listing(purchaser, cost) @@ -140,6 +159,37 @@ class ClassifiedListingsController < ApplicationController end end + def first_publish(cost) + available_author_credits = @classified_listing.author.credits.unspent + available_user_credits = [] + if @classified_listing.author.is_a?(Organization) + available_user_credits = current_user.credits.unspent + end + + if available_author_credits.size >= cost + create_listing(@classified_listing.author, cost) + elsif available_user_credits.size >= cost + create_listing(current_user, cost) + else + redirect_to credits_path, notice: "Not enough available credits" + end + end + + def bump_listing(cost) + org = Organization.find_by(id: @classified_listing.organization_id) + + available_org_credits = org.credits.unspent if org + available_user_credits = current_user.credits.unspent + + if org && available_org_credits.size >= cost + charge_credits_before_bump(org, cost) + elsif available_user_credits.size >= cost + charge_credits_before_bump(current_user, cost) + else + redirect_to(credits_path, notice: "Not enough available credits") && return + end + end + def charge_credits_before_bump(purchaser, cost) ActiveRecord::Base.transaction do Credits::Buyer.call( @@ -148,7 +198,7 @@ class ClassifiedListingsController < ApplicationController cost: cost, ) - raise ActiveRecord::Rollback unless bump_listing + raise ActiveRecord::Rollback unless bump_listing_success end end diff --git a/app/controllers/concerns/classified_listings_toolkit.rb b/app/controllers/concerns/classified_listings_toolkit.rb index 175d09cc0..387057ba9 100644 --- a/app/controllers/concerns/classified_listings_toolkit.rb +++ b/app/controllers/concerns/classified_listings_toolkit.rb @@ -24,7 +24,7 @@ module ClassifiedListingsToolkit @classified_listing.save end - def bump_listing + def bump_listing_success @classified_listing.bumped_at = Time.current saved = @classified_listing.save @classified_listing.index! if saved diff --git a/app/javascript/listings/__tests__/__snapshots__/listingDashboard.test.jsx.snap b/app/javascript/listings/__tests__/__snapshots__/listingDashboard.test.jsx.snap index e0b1332ad..8b5e5b822 100644 --- a/app/javascript/listings/__tests__/__snapshots__/listingDashboard.test.jsx.snap +++ b/app/javascript/listings/__tests__/__snapshots__/listingDashboard.test.jsx.snap @@ -63,6 +63,14 @@ preact-render-spy (1 nodes) > Active + + Draft + -