defmodule PhoenixKitWeb.Live.Modules.DBSync.Index do @moduledoc """ Landing page for DB Sync module. Presents two options: - Send Data: Generate a code and host an endpoint to share your data - Receive Data: Connect to another site to browse and pull their data """ use PhoenixKitWeb, :live_view use Gettext, backend: PhoenixKitWeb.Gettext alias PhoenixKit.DBSync alias PhoenixKit.Settings alias PhoenixKit.Utils.Routes @impl true def mount(params, _session, socket) do locale = params["locale"] || "en" project_title = Settings.get_setting("project_title", "PhoenixKit") config = DBSync.get_config() socket = socket |> assign(:page_title, "DB Sync") |> assign(:project_title, project_title) |> assign(:current_locale, locale) |> assign(:current_path, Routes.path("/admin/db-sync", locale: locale)) |> assign(:config, config) {:ok, socket} end @impl true def handle_params(_params, _url, socket) do {:noreply, socket} end @impl true def render(assigns) do ~H"""
<%!-- Header Section --%>
<.link navigate={Routes.path("/admin/modules")} class="btn btn-outline btn-primary btn-sm absolute left-0 top-0" > <.icon name="hero-arrow-left" class="w-4 h-4" /> Back to Modules

DB Sync

Transfer data between PhoenixKit instances

<%= if not @config.enabled do %>
<.icon name="hero-exclamation-triangle" class="w-5 h-5" /> DB Sync module is disabled. Enable it in <.link navigate={Routes.path("/admin/modules")} class="link link-primary"> Modules to use this feature.
<% end %> <%!-- Main Options --%>
<%!-- Send Data Card --%>
📤

Send Data

Generate a connection code and share your data with another site. They will connect to you and pull the data they need.

<.link navigate={Routes.path("/admin/db-sync/send", locale: @current_locale)} class="btn btn-primary btn-lg" > <.icon name="hero-arrow-up-tray" class="w-5 h-5" /> Share My Data
<%!-- Receive Data Card --%>
📥

Receive Data

Connect to another site using their URL and connection code to browse and pull their data into this site.

<.link navigate={Routes.path("/admin/db-sync/receive", locale: @current_locale)} class="btn btn-secondary btn-lg" > <.icon name="hero-arrow-down-tray" class="w-5 h-5" /> Pull Data
<%!-- Info Section --%>

<.icon name="hero-information-circle" class="w-5 h-5" /> How it works

1

Sender Opens API

The site with data generates a connection code and shares it

2

Receiver Connects

The site wanting data enters the URL and code to connect

3

Browse & Transfer

Browse tables, select what to import, and configure conflict handling

<%!-- Active Sessions --%> <%= if @config.active_sessions > 0 do %>
<.icon name="hero-signal" class="w-5 h-5" /> {@config.active_sessions} active transfer session(s)
<% end %>
""" end end