@@ -466,6 +534,75 @@ if (empty($application['id_number'])) {
$('#responseMessage').html(''); // Clear the message
$('#responseMessage2').html(''); // Clear the message
});
+
+ // Link User Form
+ $('#linkUserForm').on('submit', function(e) {
+ e.preventDefault();
+ const email = $('#secondary_email').val();
+ const relationship = $('#relationship').val();
+ const csrfToken = $('input[name="csrf_token"]').val();
+
+ $.ajax({
+ url: 'link_membership_user',
+ type: 'POST',
+ dataType: 'json',
+ data: {
+ secondary_email: email,
+ relationship: relationship,
+ csrf_token: csrfToken
+ },
+ success: function(response) {
+ if (response.success) {
+ $('#linkMessage').html('
' + response.message + '
');
+ $('#linkUserForm')[0].reset();
+ // Reload page after 2 seconds to show updated list
+ setTimeout(function() {
+ location.reload();
+ }, 2000);
+ } else {
+ $('#linkMessage').html('
' + response.message + '
');
+ }
+ },
+ error: function(xhr) {
+ try {
+ const response = JSON.parse(xhr.responseText);
+ $('#linkMessage').html('
' + response.message + '
');
+ } catch (e) {
+ $('#linkMessage').html('
Error linking user. Please try again.
');
+ }
+ }
+ });
+ });
+
+ // Unlink User
+ $(document).on('click', '.unlink-btn', function() {
+ const linkId = $(this).data('link-id');
+ const csrfToken = $('input[name="csrf_token"]').val();
+
+ if (confirm('Are you sure you want to remove this linked account?')) {
+ $.ajax({
+ url: 'unlink_membership_user',
+ type: 'POST',
+ dataType: 'json',
+ data: {
+ link_id: linkId,
+ csrf_token: csrfToken
+ },
+ success: function(response) {
+ if (response.success) {
+ // Reload page to show updated list
+ location.reload();
+ } else {
+ alert('Error: ' + response.message);
+ }
+ },
+ error: function() {
+ alert('Error removing linked account. Please try again.');
+ }
+ });
+ }
+ });
+
// Profile Picture Upload
$('#uploadPictureBtn').click(function() {
$('#profile_picture').click();