Merge pull request #4222 from Growstuff/feature/add-activity-prompts

feat: Add prompts for new activities
This commit is contained in:
Daniel O'Connor
2025-09-20 17:49:47 +09:30
committed by GitHub
parent 6d076983dd
commit ce7ce70d5f
5 changed files with 27 additions and 4 deletions

View File

@@ -32,6 +32,8 @@ class ActivitiesController < DataController
owner: current_member,
due_date: Date.today
)
@activity.name = params[:name] if params[:name]
@activity.due_date = params[:due_date] if params[:due_date]
if params[:garden_id]
@activity.garden = Garden.find_by(
owner: current_member,
@@ -63,7 +65,17 @@ class ActivitiesController < DataController
end
def update
@activity.update(activity_params)
if @activity.update(activity_params)
if activity_params[:finished].present?
link = new_activity_path(
name: @activity.name,
garden_id: @activity.garden_id,
planting_id: @activity.planting_id,
due_date: 2.weeks.from_now.to_date
)
flash[:notice] = t('activities.finished_prompt_html', link: link).html_safe
end
end
respond_with @activity
end

View File

@@ -39,7 +39,10 @@ class GardensController < DataController
def create
@garden.owner_id = current_member.id
flash[:notice] = I18n.t('gardens.created') if @garden.save
if @garden.save
link = new_activity_path(name: 'Weed the garden bed', garden_id: @garden.id, due_date: 2.weeks.from_now.to_date)
flash[:notice] = t('gardens.created_prompt_html', link: link).html_safe
end
respond_with(@garden)
end

View File

@@ -83,7 +83,12 @@ class PlantingsController < DataController
end
def update
@planting.update(planting_params)
if @planting.update(planting_params)
if planting_params[:finished].present? && @planting.garden.plantings.current.empty?
link = new_activity_path(name: 'Cultivate soil', garden_id: @planting.garden_id)
flash[:notice] = t('plantings.finished_prompt_html', link: link).html_safe
end
end
respond_with @planting
end

View File

@@ -125,6 +125,7 @@ en:
updated: Garden was successfully updated.
confirm_delete: All plantings associated with this garden will also be deleted. Are you sure?
confirm_deactivate: All plantings associated with this garden will be marked as finished. Are you sure?
created_prompt_html: "Garden was successfully created. Would you like to <a href=\"%{link}\">plan to weed this garden bed in two weeks</a>?"
harvests:
created: Harvest was successfully created.
harvest_something: Harvest something
@@ -301,6 +302,7 @@ en:
finish_helper: >
An activity is finished when you've completed it, or it's otherwise
no longer possible.
finished_prompt_html: "Activity finished. Would you like to <a href=\"%{link}\">repeat this activity in two weeks</a>?"
plantings:
badges:
days_until_finished: days until finished
@@ -325,6 +327,7 @@ en:
string: "%{crop} planting in %{garden} by %{owner}"
progress:
progress_0_not_planted_yet: 'Progress: 0% - not planted yet'
finished_prompt_html: "Planting was successfully updated. Would you like to <a href=\"%{link}\">plan a soil cultivation activity</a>?"
posts:
write_blog_post: Write blog post
index:

View File

@@ -187,7 +187,7 @@ describe "Planting a crop", :js, :search do
check "finished"
fill_in "Finished date", with: "2015-06-25"
click_button "Save"
expect(page).to have_content "planting was successfully updated"
expect(page).to have_content "Planting was successfully updated"
expect(page).to have_content "Finished"
end