<div class="row">
<%= form_for @recipients_changeset, checkout_sms_path(@conn, :preview_sms), [as: :sms], fn f -> %>
<div class="col s8">
<div>
<div class="row">
<div class="input-field col s12">
<label for="sms[name]">Name</label>
<%= text_input f, :name, placeholder: "Enter Name for this campaign", maxlength: 20, class: "validate", required: true %>
<%= error_tag f, :name %>
</div>
</div>
<div class="row">
<div class="input-field col s12">
<label for="sms[description]">Description</label>
<%= text_input f, :description, placeholder: "Enter Description for this campaign", maxlength: 50, class: "validate", required: true %>
<%= error_tag f, :description %>
</div>
</div>
<div class="row">
<div class="input-field col s12">
<i class="material-icons prefix">message</i>
<%= textarea f, :message, class: "materialize-textarea", id: "message", required: true %>
<label for="message">Message</label>
<%= error_tag f, :message %>
<span class="helper-text d-helper-text">Max length of text is 160 in English(alphabetic language) and other languages(Korean, Japanese, Chinese etc)'s limit is 70 character.
if you try to send message longer than a limit, it will charge double (like sending 2 messages). </span>
<span id="message-length-info" class="helper-text d-helper-text">
</span>
</div>
</div>
<%= hidden_input f, :total_credit, value: 1 %>
<div class="row">
<div class="col s12">
<button class="btn waves-effect waves-light" type="submit" name="action">Next
<i class="material-icons right">send</i>
</button>
</div>
</div>
</div>
</div>
<% end %>
<!-- Short url generation section -->
<div class="col s4">
<form>
<div class="row">
<div class="input-field col s12">
<label for="long_url">Type long URL here.</label>
<textarea class="materialize-textarea" id="long-url-textarea" name="long_url_textarea"><%= @long_url %> </textarea>
<p id="long-url-error"></p>
</div>
</div>
<div class="row">
<div class="input-field col s6">
<button class="btn waves-effect waves-light" drab="click:shorten_url">Shorten
<i class="material-icons right">content_cut</i>
</button>
</div>
</div>
</form>
<!-- Shortened Url -->
<div class="row">
<div class="input-field col s12">
<label for="long_url">Your short Url</label>
<textarea class="materialize-textarea" id="short-url-textarea"><%= @shorten_url %> </textarea>
<span class="helper-text d-helper-text">Copy this text and paste in your message. </span>
</div>
</div>
</div>
</div>
and defhandler here
defhandler shorten_url(socket, sender) do
long_url = sender.params["long_url_textarea"]
user_id = socket.assigns.current_user_id
case Analytics.create_short_link(long_url) do
{:ok, results} ->
# Create bitly struct
%{id: bitlink_id, link: bitlink_url, long_url: long_url} = results
Bitly.create_bitly(%{bitlink_id: bitlink_id, bitlink_url: bitlink_url, long_url: long_url, total_clicks: 0, user_id: user_id})
poke socket, shorten_url: bitlink_url, long_url: long_url
{:error, errors} ->
IO.puts "++++++++++++++++++++++++++++++++++++++"
IO.inspect errors
IO.puts "++++++++++++++++++++++++++++++++++++++"
set_prop socket, "#long-url-error", innerHTML: "Something wrong found in your url. Make sure including http://, for example http://www.example.com"
end
end